Skip to content

Commit

Permalink
Added support for multiple tab elements on same page.
Browse files Browse the repository at this point in the history
  • Loading branch information
samcroft committed Jun 9, 2011
1 parent 448c54c commit 2f4357a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions jquery.tabs.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
(function($){
$.fn.tabs = function() {
var dlHeight;
var el;
el = this;

el.addClass('enhance');
dlHeight = el.height();
this.each(function() {
var el = $(this);
el.addClass('enhance');
var dlHeight = el.height();

el.find('dd').hide();
var current = el.find('dt:first').addClass('current');
var currentHeight = current.next('dd').show().height();
el.css('height', dlHeight + currentHeight);
el.find('dd').hide();
var current = el.find('dt:first').addClass('current');
var currentHeight = current.next('dd').show().height();
el.css('height', dlHeight + currentHeight);
});

$('dt a').click(function(e){
e.preventDefault();

$(this).parents('dl').find('.current').removeClass('current').next('dd').hide();
var current = $(this).parent('dt').addClass('current');
var currentHeight = current.next('dd').show().height();
el.css('height', dlHeight + currentHeight);
var dlHeight = $(this).parents('dl').removeAttr('style').height();

$(this).parents('dl').css('height', dlHeight + currentHeight);
});
}
})(jQuery);
1 change: 1 addition & 0 deletions tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ body {
dl {
position: relative;
float: left;
clear: left;
width: 500px;
}
dl.enhance {
Expand Down

0 comments on commit 2f4357a

Please sign in to comment.