The problem here is that the .each
itself is synchronous.
- You can off-load your script to webworkers
- Or make an async loop yourself using
setInterval
In your case, this should work
$.fn.asyncEach = function(callback){
var i = 0;
var elements = this;
var timer = setInterval(function(){
callback.call(elements[i],elements[i]);
if(++i >= elements.length) clearInterval(timer);
},0);
}
$('.dtInputs').asyncEach(function(){
$(this).kendoDatePicker();
});
Note that I'm using timers to force asynchronous behavior. It will prevent blocking the UI, but will be significantly slower in processing.