Jquery onclick and focusout

Asked

Viewed 168 times

0

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

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

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

http://codepen.io/anchietajunior/pen/amxmYX

  • 1

    Please translate your question, this is the Stack in English.

  • Has been translated.

1 answer

0

Try something like this mate.


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');
   }
});
  • 2

    Please translate your answer, this is the Stack in English.

  • Okay @diegofm, I will change my answer.

  • It didn’t work, unfortunately.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.