Loop id from #nav links

I want to know the names of the ids from the links inside the #nav div, I'm trying to find what I have, but I haven't found anything about it.

+2


a source to share


2 answers


You can use an XPath expression to get a collection containing all the interesting nodes.

document.evaluate("//div[@id='nav']/a", document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null)

      

The above code will return a set containing all a elements that are children of the div element that has a nav id.



Here's a working example: http://jsfiddle.net/vycMP/3/

You can read more about XPath here: http://www.w3schools.com/xpath/default.asp

+1


a source


If you are doing this in a browser, I suggest using JQuery , then you can use a CSS-like selector that will make it pretty easy.



$('#nav a').each(function(index) {
    alert($(this).attr('id');
}

      

0


a source







All Articles