You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The instanceof check does not always work correctly, especially when you work with elements created in a different contexts.
To demonstrate run this on some page:
constiframe=document.createElement('iframe')document.body.append(iframe)// Create element within iframe but append it to parent documentconstiframeElement=iframe.contentDocument.createElement('div')document.body.append(iframeElement)// false because iframeElement was created in iframe contextconsole.log(iframeElementinstanceofiframeElement.ownerDocument.defaultView.Element)// true because element instance is checked against correct window contextconsole.log(iframeElementinstanceofiframe.contentWindow.Element)
Suggested changes:
Stop using getWindow function and replace it with this one.
/** * Returns boolean indicates whether given parameter is instance of Element * * @param {Object} maybeElement * @returns {boolean} */constisElement=maybeElement=>{returnmaybeElement&&'nodeType'inmaybeElement&&maybeElement.nodeType===Node.ELEMENT_NODE;};
The text was updated successfully, but these errors were encountered:
The
instanceof
check does not always work correctly, especially when you work with elements created in a different contexts.To demonstrate run this on some page:
Suggested changes:
Stop using getWindow function and replace it with this one.
The text was updated successfully, but these errors were encountered: