Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery mouseup function on left mouse button only?

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%"
    });
});
like image 618
ModernDesigner Avatar asked Dec 27 '12 01:12

ModernDesigner


1 Answers

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

        ...
    });
});
like image 149
Blender Avatar answered Sep 20 '22 12:09

Blender