0

I have a search bar that only displayed when the toggle button is clicked. The code I am using to do this is:

$("a.search-toggle").click(function(){
    $(".search-bar").slideToggle(200);
    $(this).toggleClass("open");
});

Now I am trying to find a way to auto select the input[type="search"] field when this toggle is actioned. Currently the user has to click the toggle button, then click the search field which isn't very user friendly.

Note

I am not looking for this to occur on page load, only once toggle has been activated.

halfer
  • 19,824
  • 17
  • 99
  • 186
CharlyAnderson
  • 737
  • 2
  • 14
  • 34

1 Answers1

1

This should do it

$('input[type="search"]').focus();

See the docs here

bitshift
  • 498
  • 2
  • 13