views:

76

answers:

2

Hi, I'm trying to get the innerHTML value of a node. The value is D&O. When I try to get this value using innerHTML I'm getting D &amp[semicolon] O. Is there any option to get the exact value rather than encoded value using Javascript? Please help me.

Forum prevents me from entering semicolon after &amp

A: 
element.firstChild.data;

Get the data in the text node contained in the element. If you want the text and not HTML that represents it, don't use innerHTML.

David Dorward
This only works as long as firstChild is a textNode, but if thats guaranteed then its a good fit.
Sean Kinsey
True, but the question implied that was the case.
David Dorward
+4  A: 

You can use

 return ("innerText" in node) ? node.innerText : node.textContent;

innerHTML will returns the equivalent HTML that would provide the text that you see.

Sean Kinsey
Not supported by Firefox last time I checked. http://www.quirksmode.org/dom/w3c_html.html
David Dorward
I just remembered that as well and fixed the code
Sean Kinsey
Thank you very much for your reply.This is working in Chrome and Mozilla. i need to test this in IE also
Deepa