HTML Event

HTML events are actions or occurrences that can be triggered by the user or the browser, such as a button click, mouse movement, or page load. HTML events allow you to associate JavaScript code with specific events, enabling interactivity and dynamic behavior in web pages. Here are some commonly used HTML events:


1. `onclick`: Occurs when an element is clicked.
Example: `<button onclick="myFunction()">Click me</button>`


2. `onmouseover`: Occurs when the mouse pointer moves over an element.
Example: `<img src="image.jpg" onmouseover="showTooltip()">`


3. `onkeydown`: Occurs when a key is pressed down.
Example: `<input type="text" onkeydown="handleKeyPress(event)">`


4. `onload`: Occurs when a web page or an element has finished loading.
Example: `<body onload="initializeMap()">`


5. `onsubmit`: Occurs when a form is submitted.
Example: `<form onsubmit="validateForm()">`


6. `onchange`: Occurs when the value of an input element changes.
Example: `<input type="text" onchange="updateValue()">`


7. `onfocus`: Occurs when an element receives focus.
Example: `<input type="text" onfocus="highlightInput()">`


8. `onblur`: Occurs when an element loses focus.
Example: `<input type="text" onblur="validateInput()">`


9. `onmouseenter` and `onmouseleave`: Occur when the mouse pointer enters or leaves an element.
Example: `<div onmouseenter="highlightElement()" onmouseleave="resetElement()">`


10. `onscroll`: Occurs when the user scrolls the content of an element.
Example: `<div onscroll="handleScroll()">`


These are just a few examples of HTML events. HTML events can be used with various elements to trigger JavaScript code, allowing you to create interactive and dynamic web experiences. Additionally, JavaScript provides the ability to bind events programmatically rather than using inline event attributes for better separation of concerns and code organization.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext