Skip to content

Instantly share code, notes, and snippets.

@odessy
Last active January 31, 2025 14:38
Show Gist options
  • Save odessy/2737b0f323fb22bc4e60f7c5e2c828ad to your computer and use it in GitHub Desktop.
Save odessy/2737b0f323fb22bc4e60f7c5e2c828ad to your computer and use it in GitHub Desktop.
document.addEventListener('DOMContentLoaded', function() {
const buttons = document.querySelectorAll(".btn");
buttons.forEach((btn)=>{
btn.addEventListener('click', (event)=>{
const id = btn.getAttribute("href");
const div = document.querySelector(id);
if(div){
//hide other dives
const otherDivs = div.parentNode.querySelectorAll('div[id^="q_"]');
otherDivs.forEach((other)=>{
other.style.display = 'none'
});
//show selected div
div.classList.add('fit');
div.style.display = 'block';
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment