Search code examples
javascripthtmlregexmarkup

Javascript - Can't replace "<" word in string


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 ?


Solution

  • 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");