Handling with HTML inline attribute
The HTML syntax also consists of attributes to handle events. These attributes accept function calls as values.
Syntax:
<startTag onclick="myFunction()">content</endTag>
The event handlers return an event object as the callback parameter which has the details regarding the event.
Example: We will add the same code as the first example but as an inline attribute.
Javascript
<!DOCTYPE html> <html> <head> <title>EventHandlers</title> </head> <body> <div class= "buttons" > <button onClick= "pressme()" >Press me</button> </div> <script> function pressme() { document.write( '<h1 style="color:green"> w3wiki</h1>' ); } </script> </body> </html> |
Output:
Explain about EventHandler with Example
Event handlers are the properties in the browser or DOM API that handles the response to an event. Let us understand this with an example when we click on any virtual button of the browser a particular task gets executed for us, and eventually, the browser responds to your trigger with some result, or when you hover on a browser component it gets disguised by changing its display properties. This happens with event handlers. Event handlers help you to reflect on an event occurrence.
Contact Us