Events: What and When?
These are the most common web page events:
- A page loads
- User clicks a button
- User inputs data
Theory is great, but we recommend digging deeper!
Event Handler Attributes
onclick is added to an HTML button element.
<button onclick="document.getElementById('dateOut').innerHTML = Date()">What is the time</button>
Usually, the code to be executed on the event is longer than one line. In that case, it is more convenient to use functions:
<button onclick="myFunction()">What is the time</button>
|onchange||Occurs when an HTML element changes|
|onclick||Occurs when the user clicks on an HTML element|
|onmouseover||Occurs when the user hovers their cursor over an HTML element|
|onmouseout||Occurs when the user hovers their cursor away from an HTML element|
|onkeydown||Occurs when the user presses a keyboard key|
|onload||Occurs when the current web page finishes loading|