Created
November 10, 2017 09:29
-
-
Save koldovsky/9264069678ddd944b0d4e4a77f54d2e8 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"> | |
document.querySelectorAll('.buttons') | |
.forEach(el => el.addEventListener('click', btnClick) ); | |
function btnClick(ev) { | |
document.querySelectorAll('.buttons button, .panels div') | |
.forEach( 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">document.querySelectorAll('.buttons') | |
.forEach(el => el.addEventListener('click', btnClick) ); | |
function btnClick(ev) { | |
document.querySelectorAll('.buttons button, .panels div') | |
.forEach( 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
document.querySelectorAll('.buttons') | |
.forEach(el => el.addEventListener('click', btnClick) ); | |
function btnClick(ev) { | |
document.querySelectorAll('.buttons button, .panels div') | |
.forEach( 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