function waitForElement ( query , callback ){ var poops = setInterval ( function (){ if ( document .querySelector(query)){ clearInterval ( poops ); callback (); } }, 100 ); } waitForElement ( ".class" , function (){ alert ( "element is loaded.. do stuff" ); });