Posted By

mifly on 12/16/08


Tagged

highlightKeyword


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ginoplusio


highlight keyword for table


 / Published in: JavaScript
 

  1. function highLightKeyWord(eTable,strKeyWord,className){
  2. var rows = eTable.rows;
  3. var oRegExp = new RegExp("" + strKeyWord + "","g");
  4. for(var i=0,rl=rows.length;i<rl;i++){
  5. var r = rows.item(i);
  6. for(var j=0,tl=r.cells.length;j<tl;j++){
  7. var innerText = r.cells.item(j).innerHTML;
  8. var tmp = innerText.replace(oRegExp,"<span class='"+className+"'>"+strKeyWord+"</span>");
  9. r.cells.item(j).innerHTML = tmp;
  10. }
  11. }
  12. }

Report this snippet  

You need to login to post a comment.