DEV Community

Narasimma Radhakrishnan
Narasimma Radhakrishnan

Posted on

Event Listener in JavaScript?

An event listener in JavaScript is used to execute a function when an event happens, such as clicking a button, typing in an input, or moving the mouse.

  1. Simple example click me

let button = document.getelementbyId("btn");
button.addEventListener("click", function(){
console.log("hello world");
});

  1. Common event listeners

    • Event When it happens
    • click User clicks an element
    • mouseover Mouse moves over an element
    • mouseout Mouse leaves an element
    • input Input value changes
    • change A value is changed and committed
    • keydown User presses a keyboard key
    • submit A form is submitted

Top comments (0)