JavaScript Mouse Events

The mouse events in JavaScript are those events that triggers while operating the mouse.

JavaScript Mouse Events Example

Here is an example demonstrate mouse events in JavaScript:

<!DOCTYPE HTML>
<html>
<head>
   <title>JavaScript Mouse Events</title>
</head>
<body>

<h3>JavaScript Mouse Events Example</h3>
<p>Click on the Button given below</p>
   <button onmousedown="document.images['img'].src='img2.jpg'"
   onmouseup="document.images['img'].src='img1.jpg'">
      <img name="img">
   </button>

</body>
</html>

Here are some sample outputs of the above JavaScript mouse events example. This is the initial output:

javascript mouse events

This is the output produced by the above JavaScript example after pressing the button:

javascript onmousedown onmouseup event

Here is the live demo output produced by the above mouse events example in JavaScript.

JavaScript Online Test


« Previous Tutorial Next Tutorial »