JavaScript Events
In the previous lesson, we used an event handler (also known as an intrinsic event) to trigger off a call to our function. There are many different event handlers that you can use to link your HTML elements to a piece of JavaScript.
When you write a JavaScript function, you will need to determine when it will run. Often, this will be when a user does something like click or hover over something, submit a form, double clicks on something etc.
These are examples of events.
Using JavaScript, you can respond to an event using event handlers. You can attach an event handler to the HTML element for which you want to respond to when a specific event occurs.
For example, you could attach JavaScript's onMouseover
event handler to an element and specify some JavaScript to run whenever this event occurs against that element.
Example of an Event
In this example, we use the onmouseover
event handler to run some JavaScript when the user hovers over the element.
HTML 5 Event Handlers
HTML version 5 introduced many more event handlers. I've added them to HTML5 Event Handlers, so be sure to check them out.
The event handlers listed on that page provide you with many opportunities to trigger some JavaScript from within your HTML code.