Javascript DOM onmousedown Event via HTML Tag onmousedown function

Introduction

In JavaScript:

object.onmousedown = function(){
       myScript};

This example uses the HTML DOM to assign an "onmousedown" and "onmouseup" event to a p element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p id="demo">Click me.</p>

<script>
document.getElementById("demo").onmousedown = function() {mouseDown()};
document.getElementById("demo").onmouseup = function() {mouseUp()};

function mouseDown() {/*ww w.ja v  a  2  s  .  c  om*/
  document.getElementById("demo").innerHTML = "The mouse button is held down.";
}

function mouseUp() {
  document.getElementById("demo").innerHTML = "You released the mouse button.";
}
</script>

</body>
</html>
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