DEV Community

artemismars
artemismars

Posted on

addEventListener

HTML codes

<div id='container'>
    container
</div>
Enter fullscreen mode Exit fullscreen mode

addEventListener function

this function listens to an event that is passed through the first parameter
and calls a function that is passed through the second parameter

const container = document.getElementById("container");

function backgroundToRed(event) {
    event.target.style.backgroundColor = 'red';
}

container.addEventListener('mouseover', backgroundToRed);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)