I have a function that queries the DOM and returns an array of data attributes.
var getUIDs = function () {
$list = $('.foo');
if ( $list.length ) {
return fooArray;
} else {
setTimeout(function(){
getUIDs()
}, 500);
}
}
This function can sometimes be called before .foobeing present in the DOM. Therefore, if I check every half second or so, an array will exist within a few seconds, and I can send it back.
My question is, is there an installed pattern that I have to follow that allows the function to be called, but will not get the return value until there is one?
source
share