using javascript to identify div id

liunx

Guest
I am looking everywhere for some sort of javascript that will do two things:

1. Distinguish between div id's on a page;
2. Perform a function specific to that id.

My purpose is to get all links in one section of the page (div id=main) to open in a new window, but for all side navigation links (div id=nav) to open in the parent window. This page is a blog, which means all links are being generated by the user - so I can't name each <a> tag individually. The js has to be based on a broader category - and div id seems to be just the ticket.

...that is, if anyone knows how to make that work.

Any thoughts are appreciated. I don't write js, incidentally - I just "borrow" other people's.var aAnchors=document.getElementById('main').getElementsByTagName('a');
for(var i=0; i<aAnchors.length; i++) {
// do something to each aAnchors
}

Time to learn: <!-- m --><a class="postlink" href="http://www.w3schools.com/default.aspYou">http://www.w3schools.com/default.aspYou</a><!-- m --> rock. Thanks.sorry...
am. js. retarded. please. help.

this is what i have:

var aAnchors=document.getElementById('main').getElementsByTagName('a');
for(var i=0; i<aAnchors.length; i++) {

window.open('target','_blank');
}

i'm missing something. you know what it is. i don't. please illuminate. many thanks.You are opening a file called target for each instead of the actual name of the file attached to the link.

Most people wont see any output from that code because their popup blocker will block it. Everyone else will leave never to return when they see lots of unwanted popups appear on their screen.In your document's HEAD element:<script type="text/javascript">
if (document.getElementById) onload = function () {
var e, i = 0
while (e = document.getElementById('main').getElementsByTagName('A')[i++]) {
if (e.href) e.onclick = function () {window.open (this.href, 'child'); return false}
}
}
</script>this is kick-ass! working well. thanks.
 
Back
Top