html - How to Create a link to Current Tab Using Jquery -
when go through url:www.domain.com/#ratings ,the rating tab should open ,right showing current tab in url ,but not working linking tabs
<script type="text/javascript"> $(document).ready(function () { $('.tabs a').click(function () { switch_tabs($(this)); }); switch_tabs($('.defaulttab')); }); function switch_tabs(obj) { $('.tab-content').hide(); $('.tabs a').removeclass("selected"); var id = obj.attr("rel"); $('#' + id).show(); obj.addclass("selected"); } </script> <ul class="tabs"> <li> <a href="#movies" class="defaulttab" rel="movies">tutorial</a> </li> <li> <a href="#ratings" rel="ratings">comments</a> </li> </ul> <div class="contentbox"> <div class="tab-content" id="movies">movie tab</div> <div class="tab-content" id="ratings">rating tab</div> </div>
have tried this:
$(function(){ var hash = window.location.href.split('#').pop(); var allowed = ['hello', 'world']; if(allowed.indexof(hash) == -1) hash = allowed[0]; switch_tabs($('a[href=#'+hash+']')); });
Comments
Post a Comment