Created
November 10, 2017 09:26
-
-
Save koldovsky/8410ba69891dc20ea321bc5118a37bfd to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/qehamij
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
.panels div { | |
display: none; | |
} | |
.panels .active { | |
display: block; | |
} | |
.buttons .active { | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="buttons"> | |
<button data-panel="panel-1" class="active">Button 1</button> | |
<button data-panel="panel-2">Button 2</button> | |
<button data-panel="panel-3">Button 3</button> | |
</div> | |
<div class="panels"> | |
<div id="panel-1" class="active">Panel 1</div> | |
<div id="panel-2">Panel 2</div> | |
<div id="panel-3">Panel 3</div> | |
</div> | |
<script id="jsbin-javascript"> | |
function forAll(selector, func) { | |
document.querySelectorAll(selector).forEach(func); | |
} | |
forAll('.buttons', el => el.addEventListener('click', btnClick) ); | |
function btnClick(ev) { | |
forAll('.buttons button, .panels div', el => el.classList.remove('active') ); | |
ev.target.classList.add('active'); | |
document.getElementById(ev.target.dataset.panel).classList.add('active'); | |
} | |
</script> | |
<script id="jsbin-source-css" type="text/css">.panels div { | |
display: none; | |
} | |
.panels .active { | |
display: block; | |
} | |
.buttons .active { | |
font-weight: bold; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function forAll(selector, func) { | |
document.querySelectorAll(selector).forEach(func); | |
} | |
forAll('.buttons', el => el.addEventListener('click', btnClick) ); | |
function btnClick(ev) { | |
forAll('.buttons button, .panels div', el => el.classList.remove('active') ); | |
ev.target.classList.add('active'); | |
document.getElementById(ev.target.dataset.panel).classList.add('active'); | |
} | |
</script></body> | |
</html> |
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
.panels div { | |
display: none; | |
} | |
.panels .active { | |
display: block; | |
} | |
.buttons .active { | |
font-weight: bold; | |
} |
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
function forAll(selector, func) { | |
document.querySelectorAll(selector).forEach(func); | |
} | |
forAll('.buttons', el => el.addEventListener('click', btnClick) ); | |
function btnClick(ev) { | |
forAll('.buttons button, .panels div', el => el.classList.remove('active') ); | |
ev.target.classList.add('active'); | |
document.getElementById(ev.target.dataset.panel).classList.add('active'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment