DEV Community

artemismars
artemismars

Posted on

2 1

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay