Created
May 19, 2014 20:24
-
-
Save jackmakesthings/abe5b686f7143222949f to your computer and use it in GitHub Desktop.
here's one way to handle basic toggling tabs
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
.tab { display:none; background: #ccc; padding:10px; } | |
.tab.show { display: block; } |
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
<div class="codeeditor"> | |
<ul class="buttons"> | |
<li class="button" data-lang="html">HTML</li> | |
<li class="button" data-lang="css">CSS</li> | |
</ul> | |
<div class="code-editor"> | |
<pre class="tab show html-code" >hello i am html</pre> | |
<pre class="tab css-code">hi i'm css</pre> | |
</div> | |
</div> | |
<div class="codeeditor"> | |
<ul class="buttons"> | |
<li class="button" data-lang="html">HTML</li> | |
<li class="button" data-lang="css">CSS</li> | |
</ul> | |
<div class="code-editor"> | |
<pre class="tab show html-code" >hello i am html</pre> | |
<pre class="tab css-code">hi i'm css</pre> | |
</div> | |
</div> |
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
$('.codeeditor .button').on({ | |
'click': function(e) { | |
e.preventDefault(); | |
var $this = $(this), | |
lang = $this.attr('data-lang'), | |
$block = $this.parents('.codeeditor'); | |
var $match = $block.find('.' + lang + '-code'); | |
$match.siblings().removeClass('show'); | |
$match.addClass('show'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment