Javascript DOM onmousedown Event

Introduction

Execute a JavaScript when pressing a mouse button over a paragraph:

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" onmousedown="mouseDown()" onmouseup="mouseUp()">
Click the text! //  w  w  w .j  a  v a 2 s .  com
</p>

<script>
function mouseDown() {
  document.getElementById("myP").style.color = "red";
}

function mouseUp() {
  document.getElementById("myP").style.color = "green";
}
</script>

</body>
</html>

The onmousedown event occurs when a user presses a mouse button over an element.

Bubbles:
Cancelable:
Event type:
Supported HTML tags:












Yes
Yes
MouseEvent
All HTML elements,
EXCEPT:
<base>,
<bdo>,
<br>,
<head>,
<html>,
<iframe>,
<meta>,
<param>,
<script>,
<style>, and
<title>



PreviousNext

Related