Skip to content

Instantly share code, notes, and snippets.

@wendeehsu
Created March 5, 2023 22:41
Show Gist options
  • Save wendeehsu/2b277114a8c61ec83078e6efdf1d1e60 to your computer and use it in GitHub Desktop.
Save wendeehsu/2b277114a8c61ec83078e6efdf1d1e60 to your computer and use it in GitHub Desktop.
<script>
function showDropdown(name) {
console.log(name);
const dropdowns = document.querySelectorAll(`[id^="tag-content"]`);
for (var i = 0; i < dropdowns.length; i++) {
dropdowns[i].classList.remove('show');
}
document.getElementById("tag-content-"+name).classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
for (var i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment