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

R

Robert Oschler

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.
 
R

RobG

Robert said:
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.
 
R

Robert Oschler

RobG said:
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.

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.
 
M

Martin Honnen

Robert said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top