I've used multiple tutorials to get the exact look for show/hide using jQuery, but now that I've done it's too repetitive, I've tried to edit it using variables, but it didn't work. Is there a way to avoid repetitiveness here?
$(document).ready(function() {
$(document).click(function(event) {
if ($(event.target).is(".info-icon") || $(event.target).is(".info-tab") || ($(".info-tab").has(event.target).length == 1)) {
if ($(".info-tab").height() != 0 && !$(event.target).is(".info-tab") && !($(".info-tab").has(event.target).length == 1)) {
$(".info-tab").css("max-height", "0");
} else {
if ($(".search-tab").height() != 0) {
$(".search-tab").css("max-height", "0");
setTimeout(function() {
$(".info-tab").css("max-height", "200px");
}, 300);
} else {
$(".info-tab").css("max-height", "200px");
}
}
} else if ($(event.target).is(".search-icon") || $(event.target).is(".search-tab") || ($(".search-tab").has(event.target).length == 1)) {
if ($(".search-tab").height() != 0 && !$(event.target).is(".search-tab") && !($(".search-tab").has(event.target).length == 1)) {
$(".search-tab").css("max-height", "0");
} else {
if ($(".info-tab").height() != 0) {
$(".info-tab").css("max-height", "0");
setTimeout(function() {
$(".search-tab").css("max-height", "200px");
}, 300);
} else {
$(".search-tab").css("max-height", "200px");
}
}
} else {
$(".info-tab").css("max-height", "0");
$(".search-tab").css("max-height", "0");
}
});
});
JSFiddle for what it does is here: https://jsfiddle.net/msms92/L9L0tqvp/