Linking to a particular (hidden) tab from the current page and other pages using anchors in JQuery?

家住魔仙堡 提交于 2019-12-01 21:47:07

see this:

Do this when your page loads (when dom is ready)

var tabId = location.hash; // will look something like "#h-02"

check for the hash

 if(tabId){
   $(tabId).show(); // this will fired only when url get hash
   $(tabId).siblings().hide(); // this will show only targeted tab 
                               // others get hidden
 }

what this will do when you get a url like this site.html#tab1

variable tabId will have the value #tab1

then condition in if code block will show the targeted tab

Add a common class to your tab links. When you click the link you can trigger a click on the corresponding tab.

HTML

<a href="#tab1" class="tab-link">Click here to go to tab 1</a>

JS

$('.tab-link').click(function(){
    $('ul.tabs li a[href="'+this.href+'"]').parent().click();

});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!