Apps
Apps

Reputation: 3389

How to obtain unescaped text contents of a DOM node?

I'm trying to get the contents of a DOM node, which contains the text “D&O”. When I try to get this value using innerHTML I'm getting "D&O". Is there any option to get the raw value rather than the encoded value using JavaScript?

Upvotes: 2

Views: 435

Answers (2)

Sean Kinsey
Sean Kinsey

Reputation: 38046

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.

Upvotes: 4

Quentin
Quentin

Reputation: 943571

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.

Upvotes: 0

Related Questions