How To Replace < with < and > with > using jquery
Please try this
.replace(/</g, '<').replace(/>/g, '>')
to replace these characters globally. I tried this and works like a charm :)
I have different solution then the conventional, and it will be applied to decode/encode html
Decode
var encodedString = "<Hello>";
var decodedText = $("<p/>").html(encodedString).text();
/* this decodedText will give you "<hello>" this string */
Encode
var normalString = "<Hello>";
var enocodedText = $("<p/>").text(normalString).html();
/* this encodedText will give you "<Hello>" this string
The simplest thing to do would be
$('#test').each(function(){
var $this = $(this);
var t = $this.text();
$this.html(t.replace('<','<').replace('>', '>'));
});
working edit/jsfiddle by Jared Farrish