HTML DOM Events


JavaScript provides a variety of events that can be used to trigger functions or scripts when certain actions occur on a web page. Here are some commonly used events in the HTML DOM:

click

This event occurs when an element is clicked with the mouse.

Example

Preview

submit

This event occurs when a form is submitted.

Example

Preview

keydown

This event occurs when a key is pressed down.

Example

Preview

keyup

This event occurs when a key is released.

Example

Preview

mouseenter

This event occurs when the mouse enters an element.

Example

Preview

mouseleave

This event occurs when the mouse leaves an element.

Example

Preview

load

This event occurs when the web page is fully loaded.

Example

Preview

unload

This event occurs when the web page is unloaded or closed.

Example

Preview

resize

This event occurs when the size of the browser window changes.

Example

Preview

scroll

This event occurs when the user scrolls through the web page.

Example

Preview

You can add event listeners to certain components or to the document object itself to take advantage of these events. Events can also be used to start animations, change how items appear, and perform other interactive tasks on a website. You can design dynamic and engaging online experiences for your visitors by using event listeners and the many events offered by the HTML DOM.