I have an animating search bar that is meant to hide when the user clicks outside of it. This however causes a direct click on the submit button next to it to be ignored. How can I go around this?
HTML,
<form role="search" id="searchform" method="get" action="/">
<i class="icon icon-search"></i>
<a id="search-toggle" href="#"></a>
<input type="submit" value="">
<input id="search" type="text" name="s" value="">
</form>
CSS (SCSS),
form {
margin: 0;
input {
float: right;
}
input[type="text"] {
height: 3rem;
margin: 5px 0 0 0;
padding: 0;
width: 0;
@include transition(all, .2s, ease-in-out);
&.active {
width: 80%;
padding: .5rem 1rem;
}
}
input[type="submit"] {
width: 4rem;
background-color: transparent;
}
}
a, i {
position: absolute;
line-height: 4rem;
width: 4rem;
height: 4rem;
text-align: center;
top: 0;
right: 0;
}
i {
pointer-events: none;
color: $light-grey;
font-size: 1.6rem;
z-index: 30;
padding: 3px 0 0 0;
@include transition(color, .2s, ease);
}
JS,
$('#search').focusout(function() {
$(this).removeClass('active');
});
Also tried using blur() instead of focusout(), same result.
Edit: Added some additional code. I'm having an icon and invisible link button overlaying the submit button to prevent it from submitting at once - I want to animate and display the search box first. After that box is revealed and the user types in something, this is when I run into trouble reaching the submit event. Now it requires two clicks, one to first close the box, then a second to trigger the button.