When users click outside search form (in other words they decide not to search) it should close a button. How to manage this as toggleClass(‘open’); should not be invoked.
I’m not sure what elements make up your search box, but basically, what i would do is instead bind a function to the blur event of all elements of your form, such that if none of your elements $("whatevertheelementis").is(":focus"), close the form.
Well, $('.mysearchbutton') isnt going to work because you dont have anything in your HTML that has the class “mysearchbutton”.
Essentially what you’d be looking to do is to say something like
$('.search-box').on('blur',function() {
if(!$('.search-button').is(':focus')) {
//The box has lost focus, but the span doesnt have it; so the focus went somewhere else...
$(this).parent().removeClass('open');
}
}
but without knowing which element you’re actually trying to remove classes from, s’gonna be hard to give you an exact answer.