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.
Handle event in HTML :
Various HTML event attributes:
- onblur: This event occurs when an object loses focus.
- onchange: This event occurs when the value of an element has been changed.
- onfocus: This event occurs when element get focus.
- onclick: This event occurs when user clicks on an element.
- onmouseover: This event occurs when user hover mouse pointer over an element.
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:
- Assigning event handlers using HTML event handler attributes are considered a bad practice.
- The event handler code is mixed with the HTML code, which will make the code more difficult to maintain and extend.