I have a small Chrome Extension written in javascript with jQuery that should grab some data from a web page. Target HTML looks like:
<div id="options">
<div class="option"><div class="checkbox">1</div></div>
<div class="option"><div class="checkbox">3</div></div>
<div class="option"><div class="checkbox">5</div></div>
<div class="option"><div class="checkbox">Other value</div></div>
...
</div>
<div id="result">0</div>
When any of .checkbox is checked #result will change. My task is to check .checkbox one by one and get #result for each.
var result = {};
// for each checkbox
$('#options .option').each(function(){
// check it
this.click()
// wait a bit. Of course ideally if we can wait while #result is not changed but in practice sometimes checkbox doesn't change the result. So it will be enough to wait a few seconds
// store data
result[this.text()] = $('#result').text();
// uncheck the checkbox
this.click()
// wait
});
console.log(result);
Any ideas how to wait correctly? Thanks
UPD: A little example that show my problem https://codepen.io/mihajlo-osadchij/pen/MNyazz
#resultcontent itself and then check the values of theoption. Could you give more details?