0

I am new to javascript. I created the below script to replace remove/replace few words in a webpage. It does work but this code also modifies the attributes of html elements. Is there a way to modify only the text contents of html elements and not the html elements' attributes? Here's the code.

var sa=str;
var sal=sa.length;

var tags=document.getElementsByTagName("*");
var tagl=tags.length;

var re;
var ip; 

for(var i=0;i<tagl;i++)
{
    ip=tags[i].innerHTML;

    for(var j=0;j<sal;j++)
    {
        re=new RegExp(sa[j],'gi');
        ip=ip.replace(re,"###");
    }

    tags[i].innerHTML=ip;
}
Ram
  • 21
  • 3
  • 3
    you are selecting complete DOM!! – Govind Singh Feb 09 '14 at 15:35
  • @govind I am developing a mozilla addon.The script has to remove words in all sites a user visits.So i need to check in all tags-the reason for me selecting all tags.Is that wrong?As i said i am new to javascript need help – Ram Feb 09 '14 at 15:57
  • http://stackoverflow.com/questions/7275650/javascript-replace-command-replace-page-text – willlma Feb 11 '14 at 05:17

0 Answers0