Hello I'm trying to show and hide depending on where you click. It is not generating any type of error.
The intention is that when you click, the input is opened, which it does, but when I apply the if, the else does nothing, and when you click outside it disappears.
$(document).ready(function(){
$("#lupa").on('click', function(){
//alert("Fue presionado.");
//$('#buscador-text').slideToggle('swing');
var buscador = $("#buscador-text").css;
if(buscador.display == 'none'){
buscador.animate({ width: "toggle", opacity: "1", left: '170px', display:'inline-block'}, "swing");
}
else if (buscador.display == 'inline-block') {
buscador.animate({ width: "toggle", opacity: "1", left: '70px', display:'inline-block'}, "swing");
}
});
});
#buscador{
width: 40%;
margin: 0.7em 4em;
font-size: 1.5rem;
}
input[type='search']{
font-size: 1rem !important;
margin-top: -0.8em;
position: absolute;
margin-left: -2em;
opacity: 0;
}
span{
padding-right: 1em;
}
#buscador-text{
display: none;
position: absolute;
}
<script defer src="https://use.fontawesome.com/releases/v5.0.2/js/all.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id="buscador">
<span id="lupa"><i class="fas fa-search"></i></span><input id="buscador-text" type="search" name="buscador" placeholder="Buscar...">
</section>