[Javascript] How not to use XPath
Jursa, Jan (init)
Jan.Jursa at init.de
Tue Jul 5 07:21:38 CDT 2005
Hi,
so far i got along with not using XPath.
But nowadays with Ajax and Greasemonkey and all that cool stuff going
on, I fear I will have to dive into that horrible syntax.
On the other hand, regarding this example...
var images = document.getElementsByTagName("img");
for (i = 0; i < images.length; i++) {
var n = imagesi; var src = n.getAttribute("src");
if ((src) && (src.indexOf("threadmap_inactive.gif") > 0)) {
//do stuff here
}
}
which could become this in XPath (supposedly):
//img[contains(@src, 'threadmap_inactive.gif')]
(taken from:
http://www.codestore.net/store.nsf/unid/BLOG-20050420?OpenDocument)
...i must admit it *is* much shorter... :-(
what are your experiences with XPath?
Cheers,
Jan
More information about the Javascript
mailing list