Quantcast
Channel: jQuery – Michael Grosser, the Blog
Viewing all articles
Browse latest Browse all 11

Javascript untilTimeout, like setTimeout, but waits for success

$
0
0

Perfect for situations that have no clear timeout, but only happen once.

Usage

untilTimeout(function(){
  var elements = $('.foo select');
  if(elements.length > 1){
    doStuffWith(elements)
    return true;
  }
}, 100)

Code

function untilTimeout(callback, time){
  var timer = setInterval(function(){
    if(callback()){
      clearInterval(timer);
     }
   }, time)
}

Tagged: Javascript, jQuery, JS

Viewing all articles
Browse latest Browse all 11

Trending Articles