S
S
Sergey2021-06-22 16:36:38
JavaScript
Sergey, 2021-06-22 16:36:38

Close the search form by clicking on it?

Please help with the script to close the search past its div

$('.header-search-wrapper .search-main').click(function(){
    $('.search-form-main').toggleClass('active-search');
    $('.search-form-main .search-field').focus();



<div class="header-search-wrapper">
  <span class="search-main">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-form-main clearfix">
<form role="search" method="get" class="search-form" action="' . home_url( '/' ) . '" >
 <label>
<input type="text" value="' . get_search_query() . '" name="s" class="search-field" id="s" placeholder="Поиск" />
 <input type="hidden" name="post_type" value="product" class="search-submit" >
</label>

 </form>
<div class="result-search">
    
<div class="result-search-list"></div>
</div>
 </div>
</div></code lang="html">

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2021-06-22
@Tisott

$(window).on('click', function(evt) { // слушаем все клики
  if (!evt.target.closest('.search-wrapper')) { // если клик не внутри .search-wrapper
    $('.search-wrapper').hide(); // скрываем
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question