I really hope a subject is self explaining. I am new in your site, it assisted me much occasions but this time around i had been surprised to not locate an answer on the internet. Now you ask , fairly simple. Say, i've a component produced in code:

    var elem = docuemnt.createElement('div');

If only sometime to check on have i placed it in to the DOM before or it's still virtual.

    // check if elem is placed in the DOM (it's not)

    // check - and it's finally in the document

When use jquery i'm able to write '$(elem).filter(':visible') as well as $(elem).visible() basically remember properly. But when it's in line with the same javascript, then... All i would like would be to check does the element exist only virtually or it are available in a document (but still might be not visible).

Do that:

var elem = document.createElement('div');
elem.setAttribute('id', 'my_new_div');

if (document.getElementById('my_new_div')) { } //element exists in the document.

The most secure strategy is to check directly if the element is included in the document:

function isInDocument(el) {
    var html = document.body.parentNode;
    while (el) {
        if (el === html) {
            return true;
        el = el.parentNode;
    return false;

var elem = document.createElement('div');

Use compareDocumentPosition to ascertain if the element is contained inside document. PPK has browser compatibility particulars and John Resig includes a version for IE.