I've been trying to fix this all day - so rest assured that I've come here after exhausting all of my limited capabilities. I'm no programmer by any means, but I have attempted..
I'm running WordPress and using a theme which has custom tabs.
I want to be able to link to the tabs using ahref code. E.g. www.test.com/page/#tab2 and have it open the second tab.
Here's the HTML code:
<div class="short-tabs">
<ul style="border-bottom: 1px solid #dbd6d6;">
<li><a href="">Best Food Processors</a></li>
<li><a href="">Buying Guide</a></li>
</ul>
<div style="border: none;">
this is tab1
</div>
<div style="border: none;">
this is tab2
</div>
</div>
Here's the JQUERY code that corresponds to it:
// Tabbed blocks
jQuery(".short-tabs").each(function () {
var thisel = jQuery(this);
thisel.children("div").eq(0).addClass("active");
thisel.children("ul").children("li").eq(0).addClass("active");
});
jQuery(".short-tabs > ul > li a").click(function () {
var thisel = jQuery(this).parent();
thisel.siblings(".active").removeClass("active");
thisel.addClass("active");
thisel.parent().siblings("div.active").removeClass("active");
thisel.parent().siblings("div").eq(thisel.index()).addClass("active");
return false;
});
I have no idea how to edit this to allow for linking to and from the tabs. As you can see from the HTML, I don't even need to link to #tab1 for example for them to work.
Any ideas or experts who can help? :)
JSFIDDLE Link: http://jsfiddle.net/cws1j0q7/2/
You can check the URL hash using
window.location.hash
The easiest way for example to integrate this into your code is to add the href to your links
check if the URL has a hash and trigger the click
You can also set a data-* attribute or an ID and check for that. Make sure you disable auto-scrolling if you choose to set an ID.