0

I was doing some javascript while I noticed i can't replace a "<" word inside an html tag such as

<label id="label" > <eraseme> </label>
document.getElementById('label').innerHTML = document.getElementById('label').innerHTML.replace("<eraseme>", "Replaced");

JSFiddle

Any solution ?

Kuashe
  • 41
  • 8

3 Answers3

1

I was able to get it working by using the following in the replace function.

document.getElementById('label').innerHTML = document.getElementById('label').innerHTML.replace("&lt;", "Replaced");
lhoworko
  • 1,191
  • 2
  • 13
  • 24
0

Use HTML characters "&lt;".

Unihedron
  • 10,902
  • 13
  • 62
  • 72
Mariepw
  • 51
  • 7
0

Replace < with an html number

http://jsbin.com/vehimu/1/edit

Bazinga777
  • 5,140
  • 13
  • 53
  • 92