0

I'm trying to find all instances of the word "eNews" on a page and replace it with;

<span style="text-transform: lowercase;">e</span>News 

I found a few other answers on here but they were all directed towards looking in specific classes. I tried using the all elements selector to find the word but the replace I've written just replaces the entire page:

$('*:contains("enews")').each(function () {
    $(this).html('<span style="text-transform: lowercase;">e</span>News')
});

Here is a fiddle of the sort of page set up with the word spread about the page:

https://jsfiddle.net/mxsmLLvm/

Sam Willis
  • 4,001
  • 7
  • 40
  • 59

1 Answers1

6

Try replacing like:

$('*:contains("enews")').each(function () {
  $(this).html($(this).html().replace(/enews/gi,'<span style="text-transform: lowercase;">e</span>News'));
});

Working example: https://jsfiddle.net/u9uL5xeb/

CD..
  • 72,281
  • 25
  • 154
  • 163