Detect click outside element and handle event
document.addEventListener('click', function (e) {
if (!e.target.closest('.popup')) {
var classListArray = Array.prototype.slice.call(e.target.classList);
var isSearchIcon = classListArray.indexOf('search-options__icon') > -1;
if (!isSearchIcon) {
hideAll();
}
}
});