-2

A Jquery click event is not fired with the right mouse button, only with the left one! Is there an explanation and a solution for that?

<textarea name="message"  id="message"></textarea>

$("#message").on('click', function(event) { 
     alert("ok");
 });

http://jsfiddle.net/f29vuwoL/

Thank you

Unknown developer
  • 5,414
  • 13
  • 52
  • 100
  • possible duplicate of [How to distinguish between left and right mouse click with jQuery](http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery) – Etheryte Jan 20 '15 at 18:38
  • 1
    http://stackoverflow.com/questions/4235426/how-can-i-capture-the-right-click-event-in-javascript#answer-4236294 – Alex Jan 20 '15 at 18:38
  • **The `click` event is only fired when the left mouse button is clicked.** As stated by @tymeJV use `mousedown` which applies to all three buttons, then distinguish with `e.which` as he explains. – gilbert-v Jan 20 '15 at 18:42

2 Answers2

3

You could combine the click and contextmenu events into one listener:

$("#message").on('click contextmenu', function(event) { 
    alert("ok");
});

JSFiddle

George
  • 36,413
  • 9
  • 66
  • 103
1

Use mousedown to detect all mouse events, then use event.which to determine which mouse button was pressed (1,2,3 = left, middle, right respectively)

$("#message").on('mousedown', function(e) { 
    alert(e.which);
});
tymeJV
  • 103,943
  • 14
  • 161
  • 157