2
With this code I can stop the spread of a dropdown menu by clicking on the document. It works very well. Now I would like to accomplish the same thing, but with the right click.
The magic happens thanks to event.stopPropagation();
inside onclick
what is the equivalent of this for the right click? Is it possible to use double?
Functional code.
$(document).on('click','.body-jq-dropdown',function(event){
event.stopPropagation();
});
Example
The goal is, that when the red background is enabled, it is possible to remove it with a click on the document.
$(document).on('click','.add-red-bg',function(event){
jQuery('body').addClass('body-red-habilitado');
});
$(document).on('click contextmenu','.body-red-habilitado', function(event){
event.stopPropagation();
jQuery('body').removeClass('body-red-habilitado');
console.clear();
console.log(event.type);
});
body {
background:#eee;
}
.body-red-habilitado {
background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<button class="add-red-bg">Habilitar Background RED</button>
Works only with standard click. There is a button that when clicked adds on the body the class
.body-jq-dropdown
.– John Quimera
Didn’t work with the right click?
– Sam
No, I know it’s working here... overall no, just the left, right or console will. I’ll add an example.
– John Quimera
I put an example in the question.
– John Quimera
remove the class that was added to the body by clicking on the body.
– John Quimera
I updated the answer. See if this is it :D
– Sam
Perfect.! Thx..
– John Quimera
I think you can put the two events together so I don’t have to say it again
– Sam