I need to search through a document with jQuery to find a particular word. It's actually a brand name that has to be bold and italic wherever used.
I can do this using :contain
but only on an individual element basis. I need to be able to go through anchors, lists divs etc.
$( "a:contains('brand name')" ).html().replace('brand name'....
Any ideas would be appreciated.
Update: I have got this far which works and replaces everything on a page but I now need to wrap in a span with a class. So close but stumped on this one. Again an ideas would be appreciated.
$("body *").contents().each(function() {
if(this.nodeType==3){
this.nodeValue = this.nodeValue.replace(/brandname/g, 'colour');
}
});
It's actually a brand name that has to be bold and italic wherever used
&I can do this using :contain but only on an individual element basis. I need to be able to go through anchors, lists divs etc.
But wrapping e.gdiv
inb
element isn't valid HTML markup. Not really clear what you are expecting? – Metatarsus