Return to Snippet

Revision: 44988
at April 27, 2011 02:26 by digitalclubb


Updated Code
<!-- HTML Markup Tabbed Element -->
<div id="tabs">
	<ul id="tab_nav">
		<li><a href="#tab1">Tab1 Title</a></li>
		<li><a href="#tab2">Tab2 Title</a></li>
	</ul>
	<div id="tab_contents">
		<div id="tab1" class="tab_content"><!-- Content here --></div>
		<div id="tab2" class="tab_content"><!-- Content here --></div>
	</div>
</div>
 
/* jQuery Tabbed Element
  - Avoid anonymous functions on load
  - $.fn.find with Id uses native document.getElementById()
  - $.fn.delegate eliminates the need for wasted selection
  - Cache selectors for optimisation
*/
var tabs = {
	init: function(){
		var $tab_contents = $('#tab_contents'), $tab_nav = $('#tab_nav');
		$tab_contents.find('div.tab_content:not(:first)').hide();
		$tab_nav.find('li:first').addClass('active');
		$tab_nav.delegate('li a', 'click', function(e){
			var activeTab = $(this).attr('href');
			$tab_nav.find('li').removeClass('active');
			$(this).parent().addClass('active');
			$tab_contents.find('div.tab_content').hide();
			$tab_contents.find(activeTab).fadeIn(250);
			e.preventDefault();
		});
	}
}
$(document).ready(tabs.init());

Revision: 44987
at April 26, 2011 19:48 by digitalclubb


Updated Code
<!-- HTML Markup Tabbed Element -->
<div id="tabs">
	<ul id="tab_nav">
		<li><a href="#tab1">Tab1 Title</a></li>
		<li><a href="#tab2">Tab2 Title</a></li>
	</ul>
	<div id="tab_contents">
		<div id="tab1" class="tab_content"><!-- Content here --></div>
		<div id="tab2" class="tab_content"><!-- Content here --></div>
	</div>
</div>
 
/* jQuery Tabbed Element
  - Avoid anonymous functions on load
  - $.fn.find with Id uses native document.getElementById()
  - $.fn.delegate eliminates the need for wasted selection
  - Cache selectors for optimisation
*/
var tabs = {
	init: function(){
		var $tab_contents = $('#tab_contents'), $tab_nav = $('#tab_nav');
		$tab_contents.find('div.tab_content:not(:first)').hide();
		$tab_nav.find('li:first').addClass('active').show();
		$tab_nav.delegate('li a', 'click', function(e){
			var activeTab = $(this).attr('href');
			$tab_nav.find('li').removeClass('active');
			$(this).parent().addClass('active');
			$tab_contents.find('div.tab_content').hide();
			$tab_contents.find(activeTab).fadeIn(250);
			e.preventDefault();
		});
	}
}
$(document).ready(tabs.init());

Revision: 44986
at April 26, 2011 19:48 by digitalclubb


Updated Code
var tabs = {
	init: function(){
		var $tab_contents = $('#tab_contents'), $tab_nav = $('#tab_nav');
		$tab_contents.find('div.tab_content:not(:first)').hide();
		$tab_nav.find('li:first').addClass('active').show();
		$tab_nav.delegate('li a', 'click', function(e){
			var activeTab = $(this).attr('href');
			$tab_nav.find('li').removeClass('active');
			$(this).parent().addClass('active');
			$tab_contents.find('div.tab_content').hide();
			$tab_contents.find(activeTab).fadeIn(250);
			e.preventDefault();
		});
	}
}
$(document).ready(tabs.init());

Revision: 44985
at April 22, 2011 01:46 by digitalclubb


Initial Code
<!-- HTML Markup Tabbed Element -->
<div id="tabs">
	<ul id="tab_nav">
		<li><a href="#tab1">Tab1 Title</a></li>
		<li><a href="#tab2">Tab2 Title</a></li>
	</ul>
	<div id="tab_contents">
		<div id="tab1" class="tab_content"><!-- Content here --></div>
		<div id="tab2" class="tab_content"><!-- Content here --></div>
	</div>
</div>

/*  jQuery Tabbed Element
    - Avoid anonymous functions on load
    - $.fn.find with Id uses native document.getElementById()
    - $.fn.delegate eliminates the need for wasted selection
    - Cache selectors for optimisation
*/
var tabs = {
	init: function(){
		var $tab_contents = $('#tab_contents'), $tab_nav = $('#tab_nav');
	    $tab_contents.find('div.tab_content').hide();
	    $tab_nav.find('li:first').addClass('active').show();
	    $tab_contents.find('div.tab_content:first').show();
	    $tab_nav.delegate('li a', 'click', function(e){
	        e.preventDefault();
	        var activeTab = $(this).attr('href'); 
	        $tab_nav.find('li').removeClass('active');
	        $(this).parent().addClass('active');
	        $tab_contents.find('div.tab_content').hide();
	        $tab_contents.find(activeTab).fadeIn(250);
	    });
	}
}
$(document).ready(tabs.init);

Initial URL

                                

Initial Description
jQuery Tabbed Element (CSS Not Included)

Initial Title
jQuery Tabbed Element

Initial Tags

                                

Initial Language
JavaScript