1

My issue : if i right click on a TD inside a Datatable, the following code is successfully executed :

$('#mytable tbody tr td').mousedown(function(event){
if(event.which == 3)  //1 for mouseleft button, 2 for middle, 3 for right
{   console.log("Hello");}
});

But, it works only one time !, then, each time i perform a right click again, i get a contextual Firefox menu, instead of my Jquery code.

I tried to add event.preventDefault(); event.stopPropagation(); but it doesn't work. Maybe i put it in the wrong place.

oTable = $('#mytable').DataTable({
fnDrawCallback: function () {
event.stopPropagation();
event.stopImmediatePropagation();
};

Any idea ?

6
  • try using on() method... change $('#mytable tbody tr td').mousedown(function(event){ to $(document).on('mousedown','#mytable tbody tr td', function(event){ Commented May 11, 2016 at 14:24
  • or better to use $(document).on('contextmenu', '#mytable tbody tr td', function(event){ Commented May 11, 2016 at 14:26
  • kindly check jsfiddle.net/RRR0308/7hq1o31v Commented May 11, 2016 at 14:31
  • Thank you RRR, it works fine Commented May 11, 2016 at 14:49
  • You should click on the "Post your answer" button, if you want i give you some points Commented May 11, 2016 at 14:53

1 Answer 1

1

Hi kindly check https://jsfiddle.net/RRR0308/7hq1o31v/ use return false instead of stopPropogation()

Demo Code:

HTML

<div class="div1">

</div>

<div class="msg">

</div>

CSS

.div1{
  height:200px;
  width:200px;
  background:blue;
  margin:50px;
}

jQuery

$(document).ready(function(){
    var i=1;
  $(document).on('contextmenu', '.div1', function(e){

    $('.msg').text('right clicked '+i+' times');
    i++;
    return false;
  });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.