javascript - Opening tab with anchor link not working -


as title said, i'm trying this checking hash when page loads, , trigger click on right tab, so:

javascript

   <script>     $(function () {         $(".tab-nav a").bind('click', function (e) {              e.preventdefault();     $(this).parents('li').addclass("active").siblings().removeclass("active");     $('.tab-content').removeclass('active').hide();     console.log($('.tab-content:eq('+$(this).index()+')'));     $('.tab-content:eq('+$(this).parents('li').index()+')').addclass('active').show(); });  $('.tab-nav a').first().click();  var hash = $.trim( window.location.hash ); if (hash) $('.tab-nav a[href$="'+hash+'"]').trigger('click');  });     </script> 

here's tab setup under services.html

<section class="tabs">      <ul class="tab-nav">         <li class="active"><a href="#first">first tab</a></li>         <li><a href="#second">second tab</a></li>         <li><a href="#third">third tab</a></li>     </ul>      <div class="tab-content">         <p>here's first piece of content</p>     </div>     <div class="tab-content active">         <p>my tab active i'll show first! inb4 tab 3!</p>     </div>     <div class="tab-content">         <p>don't forget me! i'm tab 3!</p>     </div>   </section> 

and when link home page services page lets second tab:

<a href="services.html#second></a>  

i'd go second tab :)

what's issue code?

you can use :

$('#mylink').click(function() { $('#tabs').tabs('select', 1); // switch second tab return false;  }); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -