I inject a style via javascript in the head of a document in this way:
var style = document.createElement("style");
document.head.appendChild(style);
style.innerHTML = "a, .left-hand { cursor:wait; }";
I’d like to know if there’s a way to check if this style is in the document (considering that there others) and how to delete it.
Thanks
Just keep the reference around, in this case the
stylevariable.To check if it’s still in the DOM, check if it has a parent using
parentNode. If it does, it’s still in the DOM. If it does not (null), it’s not in the DOM.To remove it:
Even after this, as long as something still references the style tag, in this case the
stylevariable, you can still reappend it to the DOM.removeChildonly removes the element from the DOM, and it does not clear references.