6

I have this element which animates on a mouseup function, but right now, it works for both the left and right buttons. Is there any way to only use the left button?

$(document).ready(function() {
    $("div").mouseup(function() {
        top: "-101%"
    });
});
ModernDesigner
  • 7,539
  • 10
  • 34
  • 41
  • I can't replicate your problem: http://jsfiddle.net/5etzp/ – Blender Dec 27 '12 at 01:31
  • Well, as you can see, if you click with the *left* mouse button, it displays the alert, which is fine. But you can also use the *right* mouse button, and I want to disable right-button functionality. – ModernDesigner Dec 27 '12 at 01:33
  • Hmm, it seems to be platform-specific. Try this one: http://jsfiddle.net/5etzp/1/ – Blender Dec 27 '12 at 01:35
  • Perfect! It works. Thanks. If you want to answer the question with that solution I would be happy to accept it. Otherwise I'll answer it. – ModernDesigner Dec 27 '12 at 01:38

1 Answers1

14

You can check to see which mouse button was pressed using e.which (1 is primary, 2 is middle and 3 is secondary):

$(document).ready(function() {
    $("div").mouseup(function(e) {
        if (e.which != 1) return false;    // Stops all non-left-clicks

        ...
    });
});
Blender
  • 289,723
  • 53
  • 439
  • 496