2

Possible Duplicate:
Replace all instances of a pattern with regular expressions in Javascript / jQuery
How can I use jQuery to style /parts/ of all instances of a specific word?

Say I have the code:

<div class="replace">
     <i>Blah</i>
     <u>Blah</u>
</div>

Now, I want to replace all the < within the div with something else.

If I use $('#div').html().replace('<','somethingElse'); it only replaces the first instance.

How can I replace all the instances?

Thanks

Community
  • 1
  • 1
user1083320
  • 1,836
  • 8
  • 22
  • 29
  • you need to use a little regex, Kevin B is refering to it I think correctly, /g is ur regex command to repeat after first find – SpYk3HH Mar 14 '12 at 19:20

1 Answers1

9

Use regex

"anyString".replace(/</g,'somethingElse');

If you want to replace it inside the div then try this.

$('#div').html($('#div').html().replace(/</g,'somethingElse'));
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124