[edit] I am NOT using jquery in this app.
Looking for a way to force preexisting links to open in a new window. But I only want to Apply this behavior to links appearing in a specific div element that has a classname but no ID
[edit] I am NOT using jquery in this app.
Looking for a way to force preexisting links to open in a new window. But I only want to Apply this behavior to links appearing in a specific div element that has a classname but no ID
If you're not using jQuery, first get the element that you want to apply it to.
var allDivs = document.getElementsByTagName('div');
var myDiv = null;
for (var j = 0; j < allDivs.length; j++) {
var divClass = allDivs[j].getAttribute('class');
if (divClass != null && divClass.indexof(THE_CLASS_NAME) >= 0) {
myDiv = allDivs[i];
var allAnchors = myDiv.getElementsByTagName('a');
for (var i = 0; i < allAnchors.length; a++) {
allAnchors[i].setAttribute('target', '_blank');
}
}
}
allAnchors[i].The simplest way to do this is to use jQuery:
$('div.SomeClass a').attr('target', '_blank');
Try...
<a href="javascript:window.open('www.yoursite.org')>Your Site Opens in a new window</a>