How to distinguish between left and right mouse click with jQuery

0 votes

How do you obtain the clicked mouse button using jQuery?

$('div').bind('click', function(){
    alert('clicked');
});

this is triggered by both right and left click, what is the way of being able to catch right mouse click? I'd be happy if something like below exists:

$('div').bind('rightclick', function(){ 
    alert('right mouse button is pressed');
});

Jun 13, 2022 in JQuery by gaurav
• 23,260 points
487 views

1 answer to this question.

0 votes

Using the mousedown() method:

The mousedown() method in jQuery can be used to bind an event handler to the default 'mousedown' JavaScript event. This can be used to trigger an event. The event object's 'which' property can then used to check the respective mouse button.

answered Jun 14, 2022 by gaurav
• 23,260 points

Related Questions In JQuery

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer

How to shorten repeating code with html function and return tags in jquery

Firstly note that replace() only accepts two arguments, the ...READ MORE

answered Jun 15, 2022 in JQuery by rajatha
• 7,680 points
562 views
0 votes
0 answers

jQuery.click() vs onClick

I have a huge jQuery application, and ...READ MORE

Feb 8, 2022 in Java by Rahul
• 9,670 points
531 views
0 votes
0 answers

jQuery drag event doesn't seem to have deltaX property

I am trying to create my own ...READ MORE

Aug 8, 2022 in Web Development by gaurav
• 23,260 points
245 views
0 votes
0 answers

jQuery Event.Target for caller's reference

I don't know if I have forgotten ...READ MORE

Aug 19, 2022 in Web Development by gaurav
• 23,260 points
381 views
0 votes
1 answer

How to get all css properties and events of a html element with jquery or other libraries?

You can get the computed value of ...READ MORE

answered Jun 14, 2022 in JQuery by gaurav
• 23,260 points
788 views
0 votes
1 answer

What is the difference between AJAX with JavaScript and jQuery?

JavaScript is a programming language. JQuery is ...READ MORE

answered May 30, 2022 in JQuery by gaurav
• 23,260 points
577 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP