Results of Chrome ( Followed spec1 and spec2)
button.click() - event not dispatched
button.dispatchEvent(new Event('click')); - event is dispatched
Results of Internet Explorer
button.click() - event not dispatched
button.dispatchEvent(new Event('click')); - event not dispatched
Results of Firefox
button.click() - event not dispatched
button.dispatchEvent(new Event('click')); - event not dispatched
Is there any specific reason to prevent click events that are queued on the
user interaction task source only?
What should be the behavior of other events like button.dispatchEvent(new
Event('click'))?
>From the results we can see IE and Firefox are not dispatching any click
event generated to disabled elements.
Please let me know the correct behavior.
Sample html code used to test is
<!DOCTYPE HTML>
<button disabled>Click me!</button>
<div id="log"></div>
<script>
function debug(msg, color) {
var span = document.createElement("span");
log.appendChild(span);
span.innerHTML = msg + '<br />';
if (color)
span.style.color = color;
}
button = document.querySelector('button');
log = document.getElementById('log');
wasClicked = false;
button.addEventListener('click', function(e) {
wasClicked = true;
alert('click dispatched');
});
button.click();
if (wasClicked)
debug('Receieved click event on button.click()\n', 'red');
else
debug('No click event on button.click()\n', 'green');
wasClicked = false;
button.dispatchEvent(new Event('click'));
if (wasClicked)
debug('Receieved click event on button.dispatchEvent()\n', 'red');
else
debug('No click event on button.dispatchEvent()\n', 'green');
</script>