JSFiddle - React, Tailwind, and code Playground
by abdennour
HTML
<div id="log" style="color:gray"></div>
JavaScript
$.fn.readyx=function(fn,attempts,lg){
var $th=this;
var selector=$($th).selector;
if(typeof attempts === "undefined"){
attempts=10;
}
if ( $(selector).length > 0 || attempts===0 )
{
if(typeof fn ==="function"){
fn.call($th);
}
}
else
{
var att=attempts--;
if(lg){
console.log("Not Found:"+att)
}
window.setTimeout(function(){$(selector).readyx(fn,att,lg)},100);
}
};
setTimeout(function(){
$('body').append('<div id="waitme" style="color:red" >I am the div which you wait to be loaded </div>');
},2000);
var page={
log:function(e){
$('div#log').append('<span>'+e+'</span><br />')
}
}
/*********************************************************/
$('#waitme').readyx(function(){
page.log("now, iam ready");
alert
},30);
/*********************************************************/