jquery - Add active and current state class -
how can give each , active , current class style css , onclick active state , , onload current class added. each set @ same time both have current class added div.toggle loaded , , active class added when tab another
jsfiddle - http://jsfiddle.net/zm9dl/534/
i tried , add active class , shows active 1 set of tabs viewing , , removes active class of other set
var selector = '.tabbed-reports li'; $(selector).on('click', function(){ $(selector).removeclass('active'); $(this).addclass('active'); });
here html
<ul class="tabbed-reports"> <li class="toggle1">one</li> <li class="toggle2">two</li> <li class="toggle3">three</li> <li class="toggle4">four</li> <li class="toggle5">five</li> </ul> <div class="reports-content"> <div class="toggle1"><li class="remove">remove</li>here contents of 1..</div> <div class="toggle2" style="display:none;"><li class="remove">remove</li>here contents of 2..</div> <div class="toggle3" style="display:none;"><li class="remove">remove</li>here contents of 3...</div> <div class="toggle4" style="display:none;"><li class="remove">remove</li>here contents of 4....</div> <div class="toggle5" style="display:none;"><li class="remove">remove</li>here contents of 5.....</div> </div> <ul class="tabbed-reports"> <li class="toggle11">one</li> <li class="toggle12">two</li> <li class="toggle13">three</li> <li class="toggle14">four</li> <li class="toggle15">five</li> </ul> <div class="reports-content"> <div class="toggle11"><li class="remove">remove</li>here contents of 11..</div> <div class="toggle12" style="display:none;"><li class="remove">remove</li>here contents of 12..</div> <div class="toggle13" style="display:none;"><li class="remove">remove</li>here contents of 13...</div> <div class="toggle14" style="display:none;"><li class="remove">remove</li>here contents of 14....</div> <div class="toggle15" style="display:none;"><li class="remove">remove</li>here contents of 15.....</div> </div> $('.tabbed-reports li').on('click',function(e){ $('.reports-content>.'+ e.target.classlist[0]).show().siblings().hide(); });
you need add current
class tab has default content visible on page load in case toggle1
, toggle11
this how js should like.
var selector = '.tabbed-reports li'; $(selector).on('click', function() { $(this).siblings().removeclass('active'); var classname = $(this).attr('class').replace('current', ''); console.log($(this).parent().next('.reports-content')); $(this).parent().next('.reports-content').find('div').hide(); $('.reports-content').find('.' + classname).toggle(); $(this).toggleclass('active'); });
here's working jsfiddle
Comments
Post a Comment