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?