A function with parameters is triggered when the mouse button is pressed down - Javascript DOM Event

Javascript examples for DOM Event:onmousedown

Description

A function with parameters is triggered when the mouse button is pressed down

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p onmousedown="myFunction(this,'red')" onmouseup="myFunction(this,'green')">
Click the text to change the color.
</p>//from w w  w. j  a va 2s.  c  om

<script>
function myFunction(elmnt,clr) {
    elmnt.style.color = clr;
}
</script>

</body>
</html>

Related Tutorials