'How can I check if an element still exists in the DOM?
How can I check if an element still exists in the DOM?
<div id="parent">
...
<div class="my-class"></div>
</div>
let parent = document.getElementById('parent');
let myElement = parent.getElementsByClassName('my-class')[0];
parent.remove();
function stillExists(element) {
// check if element still exists in DOM
}
stillExists(myElement) // should be false
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|