finding words that are scattered in several nodes

finding words that are scattered in several nodes

Hi, I'm finding words in a text, which code below works:

  1.  $('p *',$(frame).contents()).each(function(){
  2.     $('*',this).contents().add($(this).contents()).filter(function(){
  3. return this.nodeType==3 && $.trim($(this).text()).length>0
  4. }).each(function(){
  5.             if(!($(this).parent()).hasClass('HL')){
  6. var html=$(this).text();
  7. var compare=$(this).text();
  8. html=html.replace(new RegExp(text, "gi"),function(matched) {return "<span class='HL' style=background-color:#d2b0ff>" + matched + "</span>";});  
  9. if(compare!=html){
  10.  $(this).replaceWith(html);
  11. }
  12. }
  13. })
  14. });
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>
  1. regards