Javascript Events: W3Schools
Javascript Events: W3Schools
Javascript Events: W3Schools
w3schools.com LOG IN
JavaScript Events
❮ Previous Next ❯
When JavaScript is used in HTML pages, JavaScript can "react" on these events.
HTML Events
An HTML event can be something the browser does, or something a user does.
HTML allows event handler attributes, with JavaScript code, to be added to HTML
elements.
https://www.w3schools.com/js/js_events.asp 1/8
1/16/2021 JavaScript Events
Example
Try it Yourself »
In the example above, the JavaScript code changes the content of the element with
id="demo".
In the next example, the code changes the content of its own element (using
this.innerHTML ):
Example
<button onclick="this.innerHTML = Date()">The time is?</button>
Try it Yourself »
JavaScript code is often several lines long. It is more common to see event attributes
calling functions:
Example
<button onclick="displayDate()">The time is?</button>
https://www.w3schools.com/js/js_events.asp 2/8
1/16/2021 JavaScript Events
Try it Yourself »
Event Description
onmouseout The user moves the mouse away from an HTML element
The list is much longer: W3Schools JavaScript Reference HTML DOM Events.
Many different methods can be used to let JavaScript work with events: