$.delay is used to delay animations in a queue, not halt execution.
Instead of using a while loop, you need to recursively call a method that performs the check every second using setTimeout
:
var check = function(){
if(condition){
// run when condition is met
}
else {
setTimeout(check, 1000); // check again in a second
}
}
check();