Skip to content

Instantly share code, notes, and snippets.

@thsneumann
Created March 7, 2017 14:19
Show Gist options
  • Save thsneumann/b8339ba3ddf6f87ac8b2da5e3f471d91 to your computer and use it in GitHub Desktop.
Save thsneumann/b8339ba3ddf6f87ac8b2da5e3f471d91 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Toggle Button</title>
<style>
.tabs .tab:not(.selected) {
display: none;
}
</style>
</head>
<body>
<button class="button-toggle tabs">
<span class="tab selected">
Show tab 2
</span>
<span class="tab">
Show tab 1
</span>
</button>
<div class="tabs">
<div class="tab selected">
Tab 1
</div>
<div class="tab">
Tab 2
</div>
</div>
<script src="https://unpkg.com/jquery@3.1.1"></script>
<script>
$(document).ready(function() {
var $tabs = $(".tabs");
$(".button-toggle").on("click", function() {
var $notSelected = $tabs.find(".tab:not(.selected)");
$tabs.find(".tab.selected").removeClass("selected");
$notSelected.addClass("selected");
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment