How to hide both the input field and the search results window when the user clicks on them?
Currently, if you hover over , both and #search-btnwill appear . If you click anywhere except both disappear.#search-container#search-results#search-container
I want so that I can click #search-resultsso that both of them do not disappear.
Fiddle: https://jsfiddle.net/emils/d2sn7q6L/
HTML:
<div id="search-container">
<form id="search-form">
<input id="search" type="search">
</form>
</div>
<a id="search-btn" class="search-icon" href="#">search</a>
<div id="search-results"></div>
JS:
var searchInput = $("#search-container");
var searchResults = $("#search-results");
var showSearchInput = function() {
searchInput.show();
searchResults.show();
if(searchInput.is(":visible")) {
$("#search").focus();
}
};
$("#search-btn").hover(showSearchInput);
searchInput.focusout(function(e) {
searchInput.hide();
searchResults.hide();
});
source
share