Possible Duplicate:
How to decode HTML entities using jQuery?
I want to convert this text:
"<p>name</p><p><span style="font-size:xx-small;">ajde</span></p><p><em>da</em></p>"
to html, with tags and everything in Javascript or Jquery. How to do this?
This question is related to
javascript
jquery
There is a jQuery solution in this thread. Try something like this:
var decoded = $("<div/>").html('your string').text();
This sets the innerHTML of a new <div>
element (not appended to the page), causing jQuery to decode it into HTML, which is then pulled back out with .text()
.
Using jQuery the easiest will be:
var text = '<p>name</p><p><span style="font-size:xx-small;">ajde</span></p><p><em>da</em></p>';
var output = $("<div />").html(text).text();
console.log(output);
I think you are looking for this ?
$('#your_id').html('<p>name</p><p><span style="font-size:xx-small;">ajde</span></p><p><em>da</em></p>').text();
Source: Stackoverflow.com