sebas sebas - 1 year ago 92
jQuery Question

How To Replace &lt; with < and &gt; 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

into HTML encoded characters.

So there is a div that contains html tags like
<br />
that is converted into
&lt;b /&gt;

So I need to change it back to the HTML characters using only jQuery:



Is there a jQuery script I can use to replace those special characters with the corresponding symbols? This will mean my HTML tags will actually work and the HTML will being displayed properly on the screen?

I've tried
but i can't make it work.

The div that im trying to modify is this

<div style="font-size: 11px; width: 90%; font-family: Tahoma;" id="cotiz">&lt;strong&gt;ValuaciĆ³n&lt;/strong&gt; de InfoAuto: 35.500,00&lt;br /&gt;
CotizaciĆ³n Seleccionada: Ninguna&lt;br /&gt;
Allianz, Responsabilidad Civil: $205,25&lt;br /&gt;
Allianz, Terceros Completos: $278,85 </div>

Answer Source

The simplest thing to do would be

    var $this = $(this);
    var t = $this.text();
    $this.html(t.replace('&lt','<').replace('&gt', '>'));

working edit/jsfiddle by Jared Farrish

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download