Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Attaching Different Event Listeners to Different Event Types</title> </head> <body> <button id="myBtn">Click Me</button> <script> // Selecting button element let btn = document.getElementById("myBtn"); // Defining custom functions function sayHello() { alert("Hi, how are you doing?"); } function setHoverColor() { btn.style.background = "yellow"; } function setNormalColor() { btn.style.background = ""; } // Assigning event listeners to the button btn.addEventListener("click", sayHello); btn.addEventListener("mouseover", setHoverColor); btn.addEventListener("mouseout", setNormalColor); </script> </body> </html>