简体   繁体   中英

Change Tab Link on Click (and Already Active Anchor)

Trying to piece together js knowledge as I go here. But I have a website that will be relying on a tabbed (just 2) concept to flip between the companies two services.

So when navigating to the page, they user will be directed to Company1 and I would like to have a tab of Company 2 on the right. It will be the same domain, just domain.com#company2.

When they navigate to Company 2 directly (via domain.com#company2) I would like the tab on the right to link to Company 1.

So basically, it looks like js is the only way to do this. Something that could read the active id and style the tab accordingly.

The main function would be based on click. So if you click the tab, it switches to the non-active companies tab.

The tab itself will remain the same, all I need to change is the href.

Thanks in advance guys!

I think you could use CSS float :

$("#tab1_id").click(function(){
    $(".2tabs_class").css("float","left)
})
$("#tab2_id").click(function(){
    $(".2tabs_class").css("float","right)
})

Make sure 2 tabs are inside a div

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM