jQuery Mousedown() Event Method Example

jQuery Mousedown() Event Method Example

jQuery mousedown() event method; Through this tutorial, you will learn how to use mouse down event with HTML elements.

jQuery Mousedown() Event Method

The jQuery mouse down event occurs when the left mouse button is pressed down over the selected element.

In other words, when the mouse button is pressed down, at the time while the mouse is over the HTML element. This trigger mousedown event on html elements.

Syntax of jQuery Mousedown() Event Method

$(selector).mousedown()  

This triggers the mousedown event for selected elements.

$(selector).mousedown(function)  

Parameters of jQuery Mousedown() Event Method

  • Function :- It is an optional parameter. This executes itself when the mousedown event is triggered.

Examples of jQuery Mousedown() Event Method

Let’s see example 1 of the mousedown event.

 
<!DOCTYPE html>    
<html>    
<head>    
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>   
<script>    
$(document).ready(function(){    
    $("#first").mousedown(function(){    
       $( "span" ).text( "mouse down event triggered" ).show().fadeOut( 2000 );   
    });    
});    
</script>    
</head>    
<body>    
<h1 id="first">Click Me.!!</h1>   
<span></span>   
</body>    
</html>   

In this above mousedown example 1, you can see that mousedown() event is triggered when you mouse cursor pointer on html elements and click mouse button. The mousedown event trigger and appear some text.

Let’s see example 2 of mousedown event.
<!DOCTYPE html>
<html>
<head>
<title>jQuery Mouse Down Event</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script> 
$(document).ready(function(){
	$("#second").mousedown(function(){
	    $( this ).text("Mouse Down Triggered");
	  });
	});
</script>
</head>
<body>
<div id="second">Click Here for Preview</div>
</body>
</html>

In this mousedown event example 2, you can see that mousedown() event is triggered when you press on the element and a text message “Mouse Down Triggered” is displayed.

Recommended jQuery Tutorials

  1. jQuery | Event MouseUp () By Example
  2. Event jQuery Mouseleave By Example
  3. jQuery Event Mouseenter Example
  4. Event jQuery MouseOver() & MouseOut By Example
  5. keyup jquery event example
  6. Jquery Click() Event Method with E.g.
  7. Event jQuery. Blur By Example
  8. jQuery form submit event with example
  9. keydown function jQuery
  10. List of jQuery Events Handling Methods with examples
  11. Jquery Selector by .class | name | #id | Elements
  12. How to Get the Current Page URL in jQuery
  13. jQuery Ajax Get() Method Example
  14. get radio button checked value jquery by id, name, class
  15. jQuery Set & Get innerWidth & innerHeight Of Html Elements
  16. jQuery Get Data Text, Id, Attribute Value By Example
  17. Set data attribute value jquery
  18. select multiple class in jquery
  19. How to Remove Attribute Of Html Elements In jQuery
  20. How to Checked Unchecked Checkbox Using jQuery
  21. jQuery removeClass & addClass On Button Click By E.g.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *