Skip to content

Instantly share code, notes, and snippets.

@rniwa
Created September 6, 2018 20:05
Show Gist options
  • Save rniwa/6c502dca3e16d5816db7958ce7bab4d7 to your computer and use it in GitHub Desktop.
Save rniwa/6c502dca3e16d5816db7958ce7bab4d7 to your computer and use it in GitHub Desktop.
Dispatching click event on a radio button and observing the event phase inside a change event listener
<!DOCTYPE html>
<html>
<body>
<input type="radio">
<script>
const input = document.querySelector('input');
const clickEvent = new MouseEvent('click', {button: 0, which: 1});
input.addEventListener('change', () => {
alert(clickEvent.eventPhase);
})
input.dispatchEvent(clickEvent);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment