</> Code Corner

JavaScript · JS Tutorial · Lesson 13

JS Events

React to clicks, changes, keys and page loads.

HTML events are "things" that happen to HTML elements. JavaScript can react to these events.

Example

<button onclick="document.getElementById('demo').innerHTML = Date()">What time is it?</button>
<input onkeyup="document.getElementById('echo').innerHTML = this.value" placeholder="Type here">
<p id="demo"></p>
<p id="echo"></p>
Event Happens when
onclick The user clicks an element
onchange An element has been changed
onmouseover / onmouseout Mouse moves over / away from an element
onkeydown / onkeyup A key is pressed / released
onload The browser has finished loading the page
onsubmit A form is submitted

Keep reading “JS Events”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋