On click I want to check if foo has class of bar if not then check again after 5 seconds if so then perform action and stop checking.
jQuery(document).ready(function($) {
$( "#foo" ).click(function() {
function bar(){
if $(this).hasClass('bar') {
return true;
} else {
setTimeout(bar, 5000);
}
}
});
});
Ive tried to create a function called bar which checks if foo has class of bar if not then wait 5 seconds and try again. I am executing this once foo has been clicked but something isn't working.
How can I check a div has class if so perform an action if not check again every 5 seconds until it has a class?