Skip to content

Instantly share code, notes, and snippets.

@maximishchenko
Created May 10, 2016 18:50
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 maximishchenko/6ebefced4f790423c42d84756cd5df40 to your computer and use it in GitHub Desktop.
Save maximishchenko/6ebefced4f790423c42d84756cd5df40 to your computer and use it in GitHub Desktop.
JS Toggle Div on Button Onclick
<div id="target_div_id"></div>
<button id='button_id'>Click</button>
var button = document.getElementById('button_id');
button.onclick = function() {
var div = document.getElementById('target_div_id');
if (div.style.display !== 'none') {
div.style.display = 'none';
}
else {
div.style.display = 'block';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment