Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Last active September 27, 2022 17:03
Show Gist options
  • Save bhaireshm/c7c10c61a3b9fc3e673889b0d1f52eab to your computer and use it in GitHub Desktop.
Save bhaireshm/c7c10c61a3b9fc3e673889b0d1f52eab to your computer and use it in GitHub Desktop.
<div class="div1 d-block">
// div content
</div>
<div class="div2 d-none">
// div content
</div>
<div class="div3 d-none">
// div content
</div>
---------------------------------
toggleDivs(['div2', 'div3']); // shows div2 and div3
function toggleDivs(divName) {
if (divName && divName.length > 0) {
divName.forEach((c) => {
if ($(`.${c}`).hasClass('d-block')) {
$(`.${c}`).removeClass('d-block').addClass('d-none');
} else {
$(`.${c}`).removeClass('d-none').addClass('d-block');
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment