How to find with javascript if element exists in DOM or it's virtual (has been just created by creat

Posted by user326574 on Stack Overflow See other posts from Stack Overflow or by user326574
Published on 2010-04-27T05:47:29Z Indexed on 2010/04/27 5:53 UTC
Read the original article Hit count: 175

Filed under:
|
|
|
|

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).

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about element