-1

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
  • 762
  • 12
  • 27

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
  • 275,078
  • 51
  • 420
  • 480
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,352
  • 3
  • 26
  • 41
-3

You can use this method:

var param = '&lt;p&gt;update this post&lt;/p&gt'; 
unescape(param);
Muhammad Talha Akbar
  • 9,654
  • 6
  • 37
  • 61
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