How to active second tab instead of first one by using javascript? -
i working on project, want show second tab active on window load, active first tab. here script:
<script> $(document).ready(function() { $('#tabs div').hide(); $('#tabs div:first').show(); $('#tabs ul li:first').addclass('active'); $('#tabs ul li a').click(function() { $('#tabs ul li').removeclass('active'); $(this).parent().addclass('active'); var currenttab = $(this).attr('href'); $('#tabs div').hide(); $(currenttab).show(); return false; }); }); </script>
the problem is, when write second in place of first doesn't work. please suggest solution.
instead of using show
, hide
outside click handler , repeating logic, can trigger event specific a
element:
var $a = $('#tabs ul li a').click(function() { $('#tabs ul li').removeclass('active'); $(this).parent().addclass('active'); var currenttab = $(this).attr('href'); $('#tabs div').hide(); $(currenttab).show(); return false; }); $a.eq(1).click();
Comments
Post a Comment