WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Waiting for the dom to load JavaScript

Submitted by barnettech on Wed, 01/15/2020 - 15:43
let bDomLoaded = false;
    if (document.readyState != "loading")
    {   
        bDomLoaded = true;
    }   
    if (!bDomLoaded)
    {   
        document.addEventListener ("DOMContentLoaded", function() { MyFunction(); } );
    } else
    {   
        MyFunction();
    }