JQuery onclick and focusout

0

I have my navbar with a search button that calls a slideToogle () and displays a form with an input text inside below my navbar.

I want my form to be hidden when I lose focus or the search button is clicked again.

So my problem is this, when I click the search button with the form open, it does the same thing twice.

link

    
asked by anonymous 21.10.2016 / 06:41

1 answer

0

Try something like this fellow.

try something like this.

var i = 0;
$('#search_button').on('click', function(e){
    if(i == 0){
      i++;
      e.preventDefault();
      $searchbar.slideToggle(300);
      $('#search_form_input').focus();
   } else {
      i = 0;
      $searchbar.trigger('focusout');
   }
});
    
21.10.2016 / 12:29