Skip to content Skip to sidebar Skip to footer

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(/&lt;/g, '<').replace(/&gt;/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 = "&lt;Hello&gt;";
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 "&lt;Hello&gt;" 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('&lt','<').replace('&gt', '>'));
});

working edit/jsfiddle by Jared Farrish

Solution 4:

$('#myDivId').text(function (i, text)
{
    return text.replace('&lt;', '<').replace('&gt;', '>');
});

Solution 5:

if use underscore.js exist _.unescape(string)

Post a Comment for "How To Replace < With < And > With > Using Jquery"