Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  51] [ 2]  / answers: 1 / hits: 149756  / 12 Years ago, wed, may 23, 2012, 12:00:00

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?


More From » jquery

 Answers
8
var text = '<p>name</p><p><span style=font-size:xx-small;>ajde</span></p><p><em>da</em></p>';
var decoded = $('<textarea/>').html(text).text();
alert(decoded);


This sets the innerHTML of a new element (not appended to the page), causing jQuery to decode it into HTML, which is then pulled back out with .text().



Live demo.


[#85399] Tuesday, May 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dylondaytond

Total Points: 92
Total Questions: 88
Total Answers: 96

Location: China
Member since Fri, Jan 15, 2021
3 Years ago
dylondaytond questions
Tue, Jun 22, 21, 00:00, 3 Years ago
Thu, May 7, 20, 00:00, 4 Years ago
;