Javascript examples for jQuery Method and Property:mousedown
The mousedown() method triggers the mousedown event, or sets function as mousedown event handler.
$(selector).mousedown(function);
Parameter | Require | Description |
---|---|---|
function | Optional. | function to run when the mousedown event is triggered |
The following code shows how to Press down the left mouse button over a <div> element to insert some text:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("div").mouseup(function(){ $(this).after("<p style='color:green;'>Mouse button released.</p>"); });/*w w w . j a va2s .c o m*/ $("div").mousedown(function(){ $(this).after("<p style='color:purple;'>Mouse button pressed down.</p>"); }); }); </script> </head> <body> <div>Press down and release the mouse button over this div element.</div> </body> </html>