![]() |
VOOZH | about |
An Event is an action or occurrence recognized by the software. It can be triggered by the user or the system. Mostly Events are used on buttons, hyperlinks, hovers, page loading, etc. All this stuff gets into action(processed) with the help of event handlers.
In this article, you will learn about different types of HTML event handler attributes. Basically, to handle events in HTML, you just need to add the function in the HTML tag which is going to be executed in JavaScript when any event in HTML is fired or triggered. There are many event attributes in HTML like keyboard event, mouse event, form event, etc. which are discussed briefly.
Syntax:
Handle event in HTML :
<element onclick="myScript">
Various HTML event attributes:
Form Event
<element onblur="myScript">
<element onchange="myScript">
<element onfocus="myScript">
Example 1: When the user selects the button from the select tag, onchange() event is fired and then OnChangeFunction() is called which is present in JavaScript. So an event handler defined in the HTML can call a function defined in a script
Output:
Event
<element onclick="myScript">
<element onmouseover="myScript">
Example 2:
Output:
In above output, 'Click Me' button calls the OnClickFunction() function when it is clicked. The OnClickFunction() is a function defined in a separate <script> element.
Disadvantages of using HTML event handler attributes: