I have a form that is hidden, and a "Show" button that when pressed shows the form ... The idea is that when I click outside the element (form) it must be hidden ... The problem is that when I click on the form too it's hidden ...
It is assumed that with denial I am telling you not to hide if I press certain elements, but it does not work.
$("*:not(#boton_mostrar, #frm_nuevo)").on("click", function(){ … });
How can I avoid hiding if I press the form? Thanks in advance.
$(function(){
//oculta al hacer click fuera del elemnto (formulario)
$("*:not(#boton_mostrar, #frm_nuevo)").on("click", function(){
if ($("#frm_nuevo").is(":visible")){
$("#frm_nuevo").slideUp();
}
});
//Muestra elento (formulario)
$("#boton_mostrar").on("click", function(event){
$("#frm_nuevo").slideToggle();
event.stopImmediatePropagation();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<button id="boton_mostrar">Mostrar</button><br><br>
<form id="frm_nuevo" style="display:none">
Nombre: <input><br>
Apellido: <input><br><br>
</form>
</body>