There is input
, with the focus on which a block with search hints is opened.
$(".search_input").focus(function () { $(".hints").show(); });
How to make the block close when clicking outside input
'a and outside the block? An example can be found here by clicking on the search box.
UPD: noted that this question already exists. The proposed solution is not suitable, since it is necessary to close the block when clicking outside the block, and if the click was not on the input. Also, when using the proposed solution, my block opens and immediately closes.
Js:
$(document).mouseup(function (e) { var container = $(".hints"); if (container.has(e.target).length === 0){ container.hide(); } }); $(".search_input").focus(function () { $(".hints").show(); });
HTML:
<div class="search"> <form action="#" method="get"> <input class="search_input" type="text" placeholder="Поиск детали, например: 990190112"> <!-- settings --> <div class="settings"> <input type="radio" name="radio" id="radio1"> <label for="radio1" data-placeholder="Введите номер детали">Искать по номеру детали</label> <input type="radio" name="radio" id="radio2"> <label for="radio2" data-placeholder="Введите что-то">Если нужен этот пункт</label> <input type="radio" name="radio" id="radio3"> <label for="radio3" data-placeholder="Введите VIN-номер">Искать по VIN-номеру</label> </div> <!-- /settings --> <button class="search_btn"></button> </form> <div class="settings_btn"> <div class="arrow_up"></div> </div> <!-- hints --> <div class="hints"> <ul> <li><a href="#">17020400F3009</a></li> <li><a href="#">17020400F3009</a></li> <li><a href="#">17020400F3009</a></li> <li><a href="#">17020400F3009</a></li> <li><a href="#">17020400F3009</a></li> <li><a href="#">17020400F3009</a></li> <li><a href="#">17020400F3009</a></li> </ul> </div> <!-- /hints --> </div>
blur
event - Grundy