I am looking to do something similar to this plugin http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
But the problem I am facing is that the above plugin does not allow you to highlight words within html.
So if you are looking for my text
inside html like
this is <a href="#">my</a> text that needs highlighting
You will not get any highlighting.
Is there a way to highlight text while ignoring any html tags in between?
I would like to leave a comment but stack doesn't allow me or I can't seem to find a button for it so have to do it in an answer. There is a problem with the script. for example: Highlighting fox in the following string:
Would break the img tag:
I was working on a highlight script and solved that problem not realizing the script might have to highlight over multiple tags. Here is how I got it not to destroy tags by trying to highlight content within tags, this script highlights multiple instances within content as well but not over multiple tags:
Not sure how to combine these scripts and make a highlight over multiple tags work but will keep my eye on this thread.
I tried the accepted solution and it seems to break on complex pages such as this one (infinite recursion). Also, I don't really see the benefit of relying on jQuery, so I rewrote the code to be independent of jQuery (it's also substantially shorter and doesn't support the fancy options).
It's easy enough to add the options back in and use classes if you like.
I fiddled some RegEx which allows HTML tags at the position of whitespace chars:
JavaScript:
Try it here: http://jsfiddle.net/UPs3V/