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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -