Waiting for the dom to load JavaScript

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