Html events: Difference between revisions
From wikinotes
Line 13: | Line 13: | ||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
document.getElementById('button') | document | ||
.getElementById('button') | |||
.addEventListener('click', () => { /* do something when clicked */ }) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Registring Callbacks --> | </blockquote><!-- Registring Callbacks --> |
Revision as of 15:15, 30 July 2021
You can register javascript callbacks to be fired on HTML DOM events.
Documentation
w3schools: events https://www.w3schools.com/jsref/dom_obj_event.asp
Registring Callbacks
document .getElementById('button') .addEventListener('click', () => { /* do something when clicked */ })