onmousedown and onmouseup eventsWe will check how to use onmousedown and onmouseup events to trigger various events. To demonstrate this we will use one div layer and when Mouse is placed over it and key is pressed the event will be triggered. We need to press the key and hold it for some time to know the difference. As long as we have pressed and holding the mouse key the background color will change as per the onmousedown event. Once we release the mouse button then the event onmouseup will take over and the event associated with it to change the background color occurred.
Here is the sample code.
In above code the background color will be #f1f1f1 when page loads, then once we click and hold the left button of the mouse over this box the color will change to #f0f000. Finally the color became #90f0c0 once we release the button.
This article is written by plus2net.com team.