开发者

NodeIterator vs Xpath for DOM iterating/finding in Javascript

开发者 https://www.devze.com 2022-12-19 11:54 出处:网络
Which is better to use when iterating over D开发者_如何学COM elements or finding a a set of DOM elements.is Xpath faster?If you want to find a group of elements that are at different hiearchical level

Which is better to use when iterating over D开发者_如何学COM elements or finding a a set of DOM elements. is Xpath faster?


If you want to find a group of elements that are at different hiearchical levels and different attributes of interest then you should use Xpath.

If you just want to "iterate" one by one over a set of elements then just use the iterator.


Xpath is more clean.

EDIT: Sorry, I don't know if it is faster.


The dojo team did some research about when XPath is faster for their dojo.query interface.

See their Blog Post about it.


according to this post "The DOM traversal code is about four times faster than the XPath code." http://www.sklar.com/blog/archives/85-Speed-DOM-traversal-vs.-XPath-in-PHP-5.html

0

精彩评论

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

关注公众号