capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.33k stars 200 forks source link

getAttributeNode() doesn't have ownerDocument, ownerElement properties and cloneNode function #275

Closed dkocsis-emarsys closed 3 years ago

dkocsis-emarsys commented 3 years ago

Hello! It's been a long time.

I've found this issue recently where getting some attributeNode from an element doesn't have ownerDocument, ownerElement properties and cloneNode function.

This example below is fine in the browser but gives back undefined with happy-dom.

const div = document.createElement('div');
div.classList.add('foo');
console.log(div.getAttributeNode('class').ownerDocument);
console.log(div.getAttributeNode('class').ownerElement);

Just to give you a little context of where these findings come from, I'm using hyperhtml (@2.18.0) for template rendering which is a virtual dom library and relies on a lot of lesser known dom functions.

Have a nice day!

capricorn86 commented 3 years ago

Thanks for reporting @dkocsis-emarsys! :slightly_smiling_face:

Both Attr.ownerElement and Attr.ownerDocument are actually deprecated. You can read more about the interface here: https://developer.mozilla.org/en-US/docs/Web/API/Attr.

I have added support for it anyway, so that Happy DOM will work together with hyperhtml :slightly_smiling_face:

You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v2.20.0