I'm defining a function that should receive a DOM element node as a parameter.
There is any efficient way to validate if the element node received actually exists in the DOM?
For example if the element node received has been created through Document.createElement()
but not appended to the DOM, I want the validation fails.
I already accomplished it with the code below, but I'm afraid that checking for all DOM element nodes is not the best solution for performance.
function checkIfNodeExists(nodeElement) {
return [...document.querySelectorAll("*")].includes(nodeElement);
}
Could someone suggest a better solution or convince me that my solution is already appropriate?