I have the following code:
$('#abre-busca').click(function(event){
event.preventDefault();
$('#menu-principal-sub li').css({'opacity':0});
setTimeout(function(){
$('#menu-principal-sub li').css({'display':'none'});
$('#menu-principal-sub form').css({'display':'inline-block'});
setTimeout(function(){
$('#menu-principal-sub form').css({'opacity':1});
},100);
},500);
});
$(document).click(function(event){
if($(event.target) != $('#barra-busca')){
$('#menu-principal-sub form').css({'opacity':0});
setTimeout(function(){
$('#menu-principal-sub form').css({'display':'none'});
$('#menu-principal-sub li').css({'display':'inline-block'});
setTimeout(function(){
$('#menu-principal-sub li').css({'opacity':1});
},100);
},500);
}else{
}
});
I want to click away from #barra-busca
, close it and give space to the other elements that will be shown, however, it happens that clicking outside of it, nothing happens, and clicking on it, or elements inside it , it performs the action of hiding and showing the other elements.
How can I fix it?
FIDDLE
Site LINK