finding words that are scattered in several nodes
Hi, I'm finding words in a text, which code below works:
- $('p *',$(frame).contents()).each(function(){
- $('*',this).contents().add($(this).contents()).filter(function(){
- return this.nodeType==3 && $.trim($(this).text()).length>0
- }).each(function(){
- if(!($(this).parent()).hasClass('HL')){
- var html=$(this).text();
- var compare=$(this).text();
- html=html.replace(new RegExp(text, "gi"),function(matched) {return "<span class='HL' style=background-color:#d2b0ff>" + matched + "</span>";});
- if(compare!=html){
- $(this).replaceWith(html);
- }
- }
-
- })
- });
But the words match when they are as a whole in a textnode. the problem is when I want to find a word like this:
the word is in a paragraph:
<p><span>wo</span><span>rd</span></p>