Skip to content

Instantly share code, notes, and snippets.

@dinhanhthi
Created December 10, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinhanhthi/cc6ce14f1ce4af862e67ecf8f8c9a3a9 to your computer and use it in GitHub Desktop.
Save dinhanhthi/cc6ce14f1ce4af862e67ecf8f8c9a3a9 to your computer and use it in GitHub Desktop.
Hide / Show box
<div class="hs__title">Click here</div>
<div class="hs__content">Content</div>
var triggers = Array.from(document.querySelectorAll('[class="hs__title"]'));
window.addEventListener('click', (ev) => {
if (ev.target.classList.contains("hs__title")){
ev.target.nextSibling.classList.toggle("show");
}
}, false);
.hs__title{
border: 1px solid #666;
padding: 5px 10px;
}
.hs__content {
height: 0;
overflow: hidden;
&.show {
height: auto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment