Until all events are completed changes in html do not occur
(function(){
function sleep(ms) {
const date = Date.now();
do {
} while (Date.now() - date < ms);
}
let button = document.getElementById('update');
//basic code example:
/*button.addEventListener('click', event => {
event.target.value = 'aaa';
sleep(1000);//or another long process
event.target.value = 'bbb';
});/**/
//even so:
button.addEventListener('click', event => {
event.target.value = 'aaa';
});
button.addEventListener('click', event => {
sleep(1000);//or another long process
});
button.addEventListener('click', event => {
event.target.value = 'bbb';
});
})();
<input type="button" value="Update" name="update" id="update">
This applies to all types of events.
What is the reason for this?
Is there a way to change html during(before) the execution of event?
clicklistener on button element?Promisewhich is a common mechanism for achieving this