2

I'm facing a weird issue in firefox . stopPropagation() not working for right click in firefox in my code but if I use an alert or breakpoint before the code it will work. it working smoothly in ie,safari,chrome,opera my code is given below

jquery

$("#div-login").click(function (e) {
    e.stopPropagation();
});

then this

$("#div-login").mousedown(function (e) {
   e.stopPropagation();
});

and this too

    $("#div-login").click(function (e) {
     if(e.button ===2)
       e.stopPropagation();
    });

markup

<div="div-login">
  <fieldset>
         ---markup----
                        </fieldset>
</div>

but none of the above code is working for right click in firefox but working without a problem for left-click

I couldn't find out the problem please help....

Optimus
  • 2,200
  • 8
  • 37
  • 71

3 Answers3

1

try contextmenu, like:

$('#div-login').on("contextmenu",function(e){
   e.stopPropagation();
}); 

or

$('#div-login').on("click",function(e){
   if(e.which == 3) {  //right click
       e.stopPropagation();
   }
}); 
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
0

I think what you need is the contextmenu event

$("#div-login").on('contextmenu',function (e) {
    e.stopPropagation();
});

Demo: Fiddle

Also see: Can't use jquery's click event handler to detect right click

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

HTML

<div id="box">
    <div id="div-login"></div>
</div>

jQuery

$('#div-login').on('mousedown', function (e) {
    if(e.button == 2 ) e.stopPropagation();
});

$('#box').on('mousedown', function () {
    alert('Right');
});

Works fine for me in FF and Chrome

DEMO with stopPropagation()

DEMO without stopPropagation()

alexP
  • 3,672
  • 7
  • 27
  • 36