How can I exit the each function when the conditions was true once?
This does not work:
$$('.box div').each(function(e) {
if(e.get('html') == '') {
e.set('html', 'test');
exit;
}
});
Use .some
?
$$('.box div').some(function(e) {
if(e.get('html') == '') {
e.set('html', 'test');
return true;
} else
return false;
});
But probably you could just use
arr = $$('.box div[html=""]');
if (arr.length > 0)
arr[0].set("html", "test");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With