With this code I can stop the propagation of a dropdown menu by clicking on the document. It Works very well. Now I'd like to accomplish the same thing, but with the right click.
The magic happens thanks to event.stopPropagation();
within onclick
what is the equivalent of this for the right click? Is it possible to use dual?
Functional code.
$(document).on('click','.body-jq-dropdown',function(event){
event.stopPropagation();
});
Example
The goal is that when the red background is enabled, you can remove it by clicking 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><buttonclass="add-red-bg">Habilitar Background RED</button>