0

Possible Duplicate:
HTML Entity Decode

I want to convert this string

<p>update this post</p> 

to

<p>update this post</p>

in Javascript.

Do you have any idea? Thanks in advance.

Community
  • 1
  • 1
nobinobiru
  • 792
  • 12
  • 28

3 Answers3

4

I'd create an element, set its innerHTML and get its innerText:

var element = document.createElement('div');
element.innerHTML = '&lt;p&gt;update this post&lt;/p&gt; ';
console.log(element.innerText);

The result is:

"<p>update this post</p> "
Blender
  • 289,723
  • 53
  • 439
  • 496
0

Working example:

var text='&lt;p&gt;update this post&lt;/p&gt;';
var d = document.createElement("div");
d.innerHTML=text;
alert(d.innerText || d.text || d.textContent);
Norbert Pisz
  • 3,392
  • 3
  • 27
  • 42
-4

You can use this method:

var param = '&lt;p&gt;update this post&lt;/p&gt'; 
unescape(param);
Muhammad Talha Akbar
  • 9,952
  • 6
  • 38
  • 62
Reza Ahmadi
  • 862
  • 2
  • 11
  • 23
  • 1
    The `unescape`function (which is deprecated because it can't handle Unicode properly) doesn't work on that form of escaping. – Quentin Jan 06 '13 at 09:34