Skip to content

Instantly share code, notes, and snippets.

@renemorozowich
Created June 20, 2019 13:50
Show Gist options
  • Save renemorozowich/a35867f4159af144dc82d70d0a271c63 to your computer and use it in GitHub Desktop.
Save renemorozowich/a35867f4159af144dc82d70d0a271c63 to your computer and use it in GitHub Desktop.
Basic JS file with a toggle
// get the button
var btnContent = document.getElementById("btn-content");
// add a click event
btnContent.addEventListener("click", toggleContent);
// get the content
var content = document.getElementById("content");
// hide by default
content.style.display = "none";
// when button is clicked, show/hide
function toggleContent() {
var myContent = document.getElementById("content");
if (myContent.style.display === "none") {
myContent.style.display = "block";
} else {
myContent.style.display = "none";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment