Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  8] [ 7]  / answers: 1 / hits: 7038  / 7 Years ago, thu, july 13, 2017, 12:00:00

I got some links in my HTML built by a WordPress shortcode. Unfortunately this shortcode do not include the target property and this way I cannot make the links open in a new tab.



I am not a programmer and I'm looking for a little JS to make some links under a specific class open in a new tab.



Something like:



if (a tag is under div.newTab class) onClick {window.open in a new tab}


Hope you guys understand it!



Thank you all.


More From » css

 Answers
1
window.onload = function(){
var allLinks = document.querySelectorAll("div.newTab a");
for(var i = 0; i < allLinks.length; i++){
var currentLink = allLinks[i];
currentLink.setAttribute("target", "_blank");
}
}

[#19350] Thursday, July 13, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
krystadesiraeo

Total Points: 493
Total Questions: 93
Total Answers: 100

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
;