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 in JQuery by gaurav
• 17,580 points
28 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 by gaurav
• 17,580 points

Related Questions In JQuery

0 votes
0 answers
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 in JQuery by rajatha
• 7,040 points
27 views
0 votes
0 answers

jQuery.click() vs onClick

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

Feb 8 in Java by Rahul
• 9,000 points
36 views
0 votes
0 answers

jQuery drag event doesn't seem to have deltaX property

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

5 days ago in Web Development by gaurav
• 17,580 points
10 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,500 points
308 views
0 votes
1 answer
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 in JQuery by gaurav
• 17,580 points
71 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP