How to find with javascript if element exists in DOM or it's virtual (has been just created by creat
- by user326574
Hello. I hope a topic is self describing. I'm new on your site, it helped me much times but this time i was surprised not to find an answer on internet. The question is quite simple. Say, i have an element created in code:
var elem = docuemnt.createElement('div');
...
I wish sometime to check have i placed it into the DOM before or it is still virtual.
// check if elem is placed in the DOM (it's not)
document.getElementByTagName('body')[0].appendChild(elem);
// check - and it's finally in the document
When use jquery i can write '$(elem).filter(':visible') or even $(elem).visible() if i remember correctly. But if it's based on the same javascript, then... All i want is to check does the element exist only virtually or it can be found in a document (and still may be not visible).