Quantcast
Channel: JavaScript DOMParser access innerHTML and other properties - Stack Overflow
Viewing all articles
Browse latest Browse all 4

JavaScript DOMParser access innerHTML and other properties

$
0
0

I am using the following code to parse a string into DOM:

var doc = new DOMParser().parseFromString(string, 'text/xml');

Where string is something like <!DOCTYPE html><html><head></head><body>content</body></html>.

typeof doc gives me object. If I do something like doc.querySelector('body') I get a DOM object back. But if I try to access any properties, like you normally can, it gives me undefined:

doc.querySelector('body').innerHTML; // undefined

The same goes for other properties, e.g. id. The attribute retrieval on the other hand goes fine doc.querySelector('body').getAttribute('id');.

Is there a magic function to have access to those properties?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images