开发者

Cycle id from #nav links

开发者 https://www.devze.com 2022-12-28 01:38 出处:网络
i want to know the id names f开发者_JS百科rom links inside #nav div, i try to find what id have , but i dont find nothing about this.You can use XPath expression to get set containing all interesting

i want to know the id names f开发者_JS百科rom links inside #nav div, i try to find what id have , but i dont find nothing about this.


You can use XPath expression to get set containing all interesting nodes.

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

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

Here is working example: http://jsfiddle.net/vycMP/3/

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


If you're doing this in the browser, I suggest using JQuery, then you can use a selector similar to CSS, which would make this quite easy.

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

精彩评论

暂无评论...
验证码 换一张
取 消