function waitForElement(){ if(typeof someVariable !== "undefined"){ //variable exists, do what you want } else{ setTimeout(waitForElement, 250); } }