Mouse /Poniter Events(onclick and onmouseenter)

 HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mouse Events</title>
</head>
<body>
    <button>Click me!</button>
    <button>Click me!!</button>
    <button>Click me!!!</button>
    <button>Click me!!!!</button>

    <script src="MouseEvents.js"></script>
</body>
</html>

CSS

// let btn=document.querySelector("button");
// function sayHello(){
//     alert("Hello!!");
// }
// btn.onclick=sayHello;



let btns=document.querySelectorAll("button");

function sayHello(){
         alert("Hello!!");
    }



for(btn of btns){
 btn.onclick=sayHello;
}


function onmouse(){
    console.dir("entered a button");
}
for(btn of btns){
    btn.onmouseenter=onmouse;
}

Comments

Popular posts from this blog

Callback Hell

TODO list with DOM

Refactoring callback hell code