Definition and Usage onmousedown..
The onmousedown event occurs when a user presses a mouse button over an element.
Tip: The order of events related to the onmousedown event (for the left/middle mouse button):
Syntax:
In HTML:<element onmousedown="myScript">
In JavaScript: object.onmousedown = function(){myScript};
In JavaScript, using the addEventListener() method:
object.addEventListener("mousedown", myScript);
Definition and Usage onmouseup..
The onmouseup event occurs when a user releases a mouse button over an element.
Tip: The order of events related to the onmouseup event (for the left/middle mouse button):
Syntax:
In HTML: <element onmouseup="myScript">
In JavaScript: object.onmouseup = function(){myScript};
In JavaScript, using the addEventListener() method:
object.addEventListener("mouseup", myScript);
CODING:The onmousedown event occurs when a user presses a mouse button over an element.
Tip: The order of events related to the onmousedown event (for the left/middle mouse button):
Syntax:
In HTML:<element onmousedown="myScript">
In JavaScript: object.onmousedown = function(){myScript};
In JavaScript, using the addEventListener() method:
object.addEventListener("mousedown", myScript);
Definition and Usage onmouseup..
The onmouseup event occurs when a user releases a mouse button over an element.
Tip: The order of events related to the onmouseup event (for the left/middle mouse button):
Syntax:
In HTML: <element onmouseup="myScript">
In JavaScript: object.onmouseup = function(){myScript};
In JavaScript, using the addEventListener() method:
object.addEventListener("mouseup", myScript);
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click me.</p>
<button id="button1">Click ME!</button>
<button onmousedown="mouseDown()" onmouseup="mouseUp()">CLicl ME!</button>
<button id="button2">Click ME!</button>
<script>
document.getElementById("button1").addEventListener("mousedown", mouseDown);
document.getElementById("button1").addEventListener("mouseup", mouseUp);
document.getElementById("button2").onmousedown = function() {mouseDown()};
document.getElementById("button2").onmouseup = function() {mouseUp()};
function mouseDown() {
document.getElementById("demo").innerHTML = "The mouse button is held down.";
}
function mouseUp() {
document.getElementById("demo").innerHTML = "You released the mouse button.";
}
</script>
</body>
</html>
<html>
<body>
<p id="demo">Click me.</p>
<button id="button1">Click ME!</button>
<button onmousedown="mouseDown()" onmouseup="mouseUp()">CLicl ME!</button>
<button id="button2">Click ME!</button>
<script>
document.getElementById("button1").addEventListener("mousedown", mouseDown);
document.getElementById("button1").addEventListener("mouseup", mouseUp);
document.getElementById("button2").onmousedown = function() {mouseDown()};
document.getElementById("button2").onmouseup = function() {mouseUp()};
function mouseDown() {
document.getElementById("demo").innerHTML = "The mouse button is held down.";
}
function mouseUp() {
document.getElementById("demo").innerHTML = "You released the mouse button.";
}
</script>
</body>
</html>
Comments
Post a Comment