Last active
March 15, 2020 08:37
-
-
Save rslahmed/a2ae92f1d7ba7882b43170e75d513420 to your computer and use it in GitHub Desktop.
accordion one open only
This file contains hidden or 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 acc = document.getElementsByClassName("sh-box-content"); | |
var panel = document.getElementsByClassName('sh-details'); | |
for (var i = 0; i < acc.length; i++) { | |
acc[i].onclick = function() { | |
var setClasses = !this.classList.contains('active'); | |
setClass(acc, 'active', 'remove'); | |
setClass(panel, 'show', 'remove'); | |
if (setClasses) { | |
this.classList.toggle("active"); | |
this.nextElementSibling.classList.toggle("show"); | |
} | |
} | |
} | |
function setClass(els, className, fnName) { | |
for (var i = 0; i < els.length; i++) { | |
els[i].classList[fnName](className); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment