JavaScript Events

What is an event?

  1. Something the browser does.
  2. Something the user does.

Visit W3 Schools for a more complete list.

Examples

On Click

Specifies a JavaScript action when a user clicks on an element.

Click Me

<div id="click"
onclick="document.getElementById('click').innerHTML = 'Thank you.';">
Click Me
</div>

On Mouse Over and On Mouse Out

Hover over me.

<div id="mouse"
onmouseover="document.getElementById('mouse').style.backgroundColor = 'red';"
onmouseout="document.getElementById('mouse').style.backgroundColor = 'blue';">
Hover over me.
</div>