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
$('#myDivId').text(function (i, text)
{
return text.replace('<', '<').replace('>', '>');
});
All of the above didn't really work for me because what I needed was something to replace all <
to < and >
to > , not only the first one.
What I did was:
.split('<').join('<').split('>').join('>');
Just thinking out of the box here. It worked for me, I hope it does for you too.
Try This:-
var wrapper=$(".contentwrap").html();
wrapper=wrapper.replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&');
$(".contentwrap").html(wrapper);
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
Use $this.html('...'); instead $this.text('...');
I needed to step to find an H1 then parse the next element, because I wasn't able to use a specific ID like you did. Good tip!
$('#sscContent').find("h1").next().each(function(){
var $this = $(this);
var t = $this.text();
$this.html(t.replace('<','<').replace('>', '>'));
});