469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Fast way to find a text node element in DOM tree?

What's a good way to find a specific text node element in a web page's DOM
tree? I thought of traversing each node but there has to be a faster way.
Is there a "find text node by nodeValue" function or something? I do know
the nodeValue (text string) of the text node.

Thanks.
Aug 29 '05 #1
3 5236
Robert Oschler wrote:
What's a good way to find a specific text node element in a web page's DOM
tree? I thought of traversing each node but there has to be a faster way.
Is there a "find text node by nodeValue" function or something? I do know
the nodeValue (text string) of the text node.


What property do you intend to use to find it? It it selected by the
user? clicked on? a navigable element such as an anchor, link or input?

Using 'find by value' may be a tad difficult if you don't know the value
to find by.
--
Rob
Aug 29 '05 #2

"RobG" <rg***@iinet.net.au> wrote in message
news:uh*****************@news.optus.net.au...
Robert Oschler wrote:
What's a good way to find a specific text node element in a web page's DOM tree? I thought of traversing each node but there has to be a faster way. Is there a "find text node by nodeValue" function or something? I do know the nodeValue (text string) of the text node.


What property do you intend to use to find it? It it selected by the
user? clicked on? a navigable element such as an anchor, link or input?

Using 'find by value' may be a tad difficult if you don't know the value
to find by.
--
Rob


RobG,

Property? The nodeValue. For a text node element the text is stored in the
nodeValue property. I'm just trying to find a way to either get a
collection of only text nodes, so I can scan their nodeValue's, or anything
that saves me from traversing the whole DOM tree.

Thanks.
Aug 29 '05 #3

Robert Oschler wrote:
Property? The nodeValue. For a text node element the text is stored in the
nodeValue property. I'm just trying to find a way to either get a
collection of only text nodes, so I can scan their nodeValue's, or anything
that saves me from traversing the whole DOM tree.


Mozilla could do it using its XPath on HTML implementation, Mozilla and
Opera 8 should be able to do it using a TreeWalker, and Opera 8 also
implements NodeIterator
(<http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html>). So
with those browsers you have options to look only at text nodes if needed.
IE does not have any W3C DOM Level 2 traversal but it has an
implementation of text searching within text ranges and then you can
expand the range to the parent element.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jürgen Holly | last post: by
12 posts views Thread by pillepop2003 | last post: by
6 posts views Thread by Ron Brennan | last post: by
5 posts views Thread by Richard Lewis | last post: by
1 post views Thread by David Hirschfield | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.