How To Replace < With < And > With > Using Jquery
I have a page that is part of a backend CRM admin panel. On that page the HTML output comes from some PHP functions that I can't access. And that HTML automatically changes < an
Solution 1:
Please try this
.replace(/</g, '<').replace(/>/g, '>')
to replace these characters globally. I tried this and works like a charm :)
Solution 2:
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
Solution 3:
The simplest thing to do would be
$('#test').each(function(){
var $this = $(this);
var t = $this.text();
$this.html(t.replace('<','<').replace('>', '>'));
});
Solution 4:
$('#myDivId').text(function (i, text)
{
return text.replace('<', '<').replace('>', '>');
});
Solution 5:
if use underscore.js exist _.unescape(string)
Post a Comment for "How To Replace < With < And > With > Using Jquery"