What I desire At the moment, the search box opens and closes when the font awesome search icon is clicked. However, I also want the option for the search box to close if the user clicks anywhere within the body.
Screenshot
[
My Custom Code
<div id="searchbox">
<form action="">
<input type="text" name="q">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<i class="fa fa-search" onclick="closeSearch()"; ></i>
<script>
function closeSearch() {
var x = document.getElementById("searchbox");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>