I have a situation where I need a returned value by calling the function. The scenario is following:
- click on dom element,
- with setTimeout() wait for another element is disappeared (the sign of the process is over),
- afterwards fetch the value and return
The point is that I'm able to achieve the desired point with callbacks or nested functions, I can alert or assign to some global variable. But I need to return it from the function as it'll be called from C# HtmlDocument invokeScript() method.
Here is an example code:
function getValue() {
$('#myElement').click();
return waitFor();
}
function waitFor() {
if($('#another').hasClass('active')) {
setTimeout(function() {waitFor();}, 100);
} else {
// alert ($('#desiredValue').text());
return $('#desiredValue').text();
}
}
getValue();