Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript string replace &lt; into <

Hey all, I basically output content into a div like this using jquery:

var text = $("#edit").val();
$("#output").text(text);

But I want to turn "&lt;" and "&gt;" into "<" and ">".

text.replace(/&lt;/,"<"); doesn't seem to be working for me...

Any ideas? Many thanks

like image 996
Tim Avatar asked Mar 14 '11 17:03

Tim


1 Answers

You could use something like the unescapeHTML() function in prototype...

Adapted from prototype js source

function unescapeHTML(escapedHTML) {
  return escapedHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
}
like image 137
Quintin Robinson Avatar answered Sep 25 '22 15:09

Quintin Robinson