JS DOM: Get elements by text content.
Posted
by hristo
on Stack Overflow
See other posts from Stack Overflow
or by hristo
Published on 2010-05-01T18:22:39Z
Indexed on
2010/05/01
18:27 UTC
Read the original article
Hit count: 210
Hello!
I am looking for a way to perform fulltext search on the DOM tree with JS. In two words, I would like to retrieve the list of text nodes which contain a given string.
I've tried mootools' Element.getElements ( ':contains[string]' )
but I can't get it to work with strings containing whitespace.
I'm thinking about simply indexing all text nodes and checking against each node for the string being searched for, but, in my project, there's no way of telling when the DOM updates in order to maintain such an index up-to-date.
Any better ideas?
Thanks
© Stack Overflow or respective owner