[Greasemonkey] nodeTree...

Aaron Boodman zboogs at gmail.com
Wed Jul 13 17:35:27 EDT 2005


It depends on whether there's any whitespace. DOM is finicky about
whitespace (http://www.mozilla.org/docs/dom/technote/whitespace/). But
what you have seems like it should work to get to the <font>. Note
that you need to go further to actually change the text (see below).

The other guys, despite being totally unhelpful, are right. It's
easier to use xpath to solve this. You can learn about it here:

http://diveintogreasemonkey.org/patterns/match-attribute.html

Also, you have an especially simple case here, so the
getElementsByTagName() method could also be used, which is a little
easier. The tag you're looking for is the zeroeth (only) <font> tag in
the subtree below <td>, so to get it, you can do:

td.getElementsByTagName("font")[0]

also note that if you actually want to change the text, what you're
looking for is not the <font> node, but the text node within it. (see
the moz docs I linked above). So you'd do:

td.getElementsByTagName("font")[0].firstChild.nodeValue = "monkey";

or, using xpath

document.evaluate("b/b/font/text()", td, null,
XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue.nodeValue =
"monkey";

- a


More information about the Greasemonkey mailing list