onmousedown = mouseDown(); - Javascript DOM Event

Javascript examples for DOM Event:Element Event Attribute

Description

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

Summary

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

Demo Code

ResultView the demo 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() {//  w ww . j a v  a2  s.c o  m
    document.getElementById("demo").innerHTML = "The mouse button is held down.";
}

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

</body>
</html>

Related Tutorials