Begin Web Programming with PHP & MySQL

Advertisements



JavaScript Events

An HTML event can be something the browser does, or something a user does. HTML events are something that happens to the HTML elements. When JavaScript is used in HTML pages, it can react to these events.

We attach an event handler to respond to an event. This is usually a JavaScript function that runs when the event occurs. Some examples of HTML events are:

  • Web page has finished loading
  • An HTML textbox was changed or focused
  • An HTML button was clicked
  • Hover the mouse over an HTML element

There are different types of events in JavaScript that are used to react to events. Here, we will discuss some of the most commonly used events like:

  • Onclick
  • Onkeyup
  • Onmouseover
  • Onload
  • Onfocus

We can bind these events either as inline or in an external script.