NodeIterator vs Xpath for DOM iterating/finding in Javascript
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
精彩评论