/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(function($){ $.fn.tabisha = function(o){ var o = $.extend({ activeClass: 'active', items: '.item', clickThings: 'ul.nav li a' }, o); // Loop through each in case there are multiple selected return $(this).each(function(){ var that = $(this), item = $(that).find(o.items), clickThings = $(that).find(o.clickThings); // no point doing anything if here is only 1 item if (2 > item.length) return; // Hide all but the first item.hide().eq(0).show(); clickThings.eq(0).parent().addClass(o.activeClass); // Loop through each clickthings clickThings.each(function(i){ // Apply click event to the clicky item $(this).click(function(){ // Sets active state $(this).parent().siblings().removeClass(o.activeClass); $(this).parent().addClass(o.activeClass); //that.hide().show(); item.hide().show(); //clickThings.hide().show(); // Show the right content item.hide().eq(i).show(); return false; }); }); }); }})(jQuery);