Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use GetElementsByClassName on created document

Tags:

javascript

dom

I created a document in Javascript using

newdoc = document.implementation.createHTMLDocument('Whatever')

and then I used

newdoc.innerHTML = document.innerHTML

to give him some code. The problem is that the DOM for newdoc doesn't seem to be fully formed and executing a function such as

newdoc.getElementsByClassName('somename')

on it yields undefined results. Do you know a solution for this problem?

like image 587
Fabrizio Serra Avatar asked Mar 25 '26 12:03

Fabrizio Serra


1 Answers

document does not have innerHTML property.

You should use it on the body.

newdoc.body.innerHTML = document.body.innerHTML;
like image 108
xdazz Avatar answered Mar 28 '26 01:03

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!