(function(){
function returnResult(result){
return result
};
setTimeout(function(){
var result = window.document.querySelector('.element span').textContent.match(/\d+/)[0];
returnResult(result)
},500);
})()
I'm trying to wait a set amount of time to pull data from an element on a page for web tracking purposes. The element takes a few milliseconds to load and loads dependably, so I don't need to try and do the whole mutation observer wait for the element to appear thing.
I'm just trying to figure out how to get a value out of setTimeout. I read over a similar question on here and it seems you have to do whatever you wanted to do with the data from within setTimeout and you cannot return data out of setTimeout.
Is there another way to make setTimeout synchronous so that it is blocking of the code that follows it so something like the below would work?
(function(){
setTimeout(function(){},500);
return window.document.querySelector('.element span').textContent.match(/\d+/)[0];
})()