Created
December 10, 2020 10:44
-
-
Save dinhanhthi/cc6ce14f1ce4af862e67ecf8f8c9a3a9 to your computer and use it in GitHub Desktop.
Hide / Show box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="hs__title">Click here</div> | |
<div class="hs__content">Content</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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