I have been trying to figure this out for a few hours, and it isn't working. Basically, on the frontend of a node with horizontal tabs, I need to have additional links that can switch the display of the tabs to the specific tab. My guess was to use the fragment url (#some_fieldset_id), but that does not work. It only switches to that tab if the page is loaded with that fragment, not when the link href is the fragment.
The other solution I have tried has been to trigger a click on the tab element, but no luck there either. The short code I tried unsuccessfully was this:
$('.horizontal-tab-button-1').trigger('click');
Does anybody have a quick and easy solution?
Much appreciated!
Comments
Comment #1
nils.destoop commented.horizontal-tab-button-1 is the list item. You need to trigger the click event from the link inside that list item.
$('.horizontal-tab-button-1 a').trigger('click');should do the trickComment #2
geraldito commentedThanks, that works.
Comment #3
MO-2 commentedHow did you implement the above code? What would I need to do to create links to specific tabs? I'm a noob to php and would like to place a link on the node view page to each tab.
Comment #4
nils.destoop commentedThe above code is javascript code. So if you add it to you themes javascript, this should work.
You have following link:
<a href="#" class="open-tab-1">open</a>Then you have following js in your javascript file:
$('a.open-tab-1).bind('click', function() { $('.horizontal-tab-button-1 a').trigger('click');});Comment #5
MO-2 commented@zuuperman
Thanks for the tip - I think I'm close.
I created this link (going for 3rd tab over - i.e., tab-2)
<a href="#tab2" class="open-tab-2">open</a>I updated my theme's js file a few different ways. Here are my attempts:
Attempt #1
Attempt #2
Also, can you confirm that this is a different technique to the one on this thread?
https://drupal.org/node/1917674#comment-7839693
The use case I'm trying to solve is where you have links at the top of the page to each tab and that clicking the links will:
1 - open the tab
2 - jump to the tab anchor on the page
3 - not reload the page
Anymore hints or help? Thanks ahead of time!
Comment #7
Dmytro Litvinchuk commentedThanks a lot! It also to work for Drupal 8. I created a module that adds bookmark link for Field Group.
Module here
Comment #8
dadderley commentedThe code in #4 works really well in Horizontal Tabs.
One thing though, if you use
<a href="#" class="open-tab-1">open</a>it will open the tab but go to the top of the page.
This works much nicer
<a href="javascript:void(0);" class="open-tab-1">open</a>