Skip to content

Instantly share code, notes, and snippets.

@smykes
Created August 16, 2019 19:36
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 smykes/3f74ae9bf607aada846f5241257514d9 to your computer and use it in GitHub Desktop.
Save smykes/3f74ae9bf607aada846f5241257514d9 to your computer and use it in GitHub Desktop.
VwZjaXw
<button id="click-1">
Test
</button>
<div class="drawer hide">
<button class="btn" id="red">Red</button>
<button class="btn" id="green">Green</button>
</div>
document.getElementById("click-1").addEventListener("click", function() {
const test = document.getElementsByClassName("drawer")[0];
// console.log(test.classList);
console.log(test.classList[1]);
if (test.classList[1] === "hide") {
test.classList.remove("hide");
} else {
test.classList.add("hide");
}
});
const btns = document.getElementsByClassName('btn');
console.log(btns.length);
for (let i = 0; i < btns.length; i+=1) {
document.getElementsByClassName('btn')[i].addEventListener('click', function() {
alert();
});
}
.drawer {
&.hide {
display: none;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment