Mouse(Event) button(Property) tutorial in JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Mouse(Event) Button(Property) JavaScript</title>
<link rel="stylesheet" href="css/Mouse(Event)_Button(Property)_JavaScript.css">
</head>
<body>
<div id="box"></div>
<script>
var target = document.querySelector("#box");
target.addEventListener("mousedown", function (e) {
console.clear();
var text = "You Pressed mouse button : " + e.button;
console.log(text);
var textTwo = e.button;
var color;
switch (textTwo) {
case 0:
color = "green";
break;
case 1:
color = "blue";
break;
case 2:
color = "red";
break;
default:
color = "pink";
break;
}
target.style.backgroundColor = color;
console.log(color);
});
</script>
</body>
</html>
Below File is css/Mouse(Event)_Button(Property)_JavaScript.css File
.png)
.png)
.png)
Comments
Post a Comment