So I've got two tabs on a page, with anchor tags- I navigate to them from the homepage using the anchor on a header menu item.
I've gotten the actual tabs to work, using an active class and aria-expanded="true", but I can't get the appropriate tab to be active from the header.
i.e.:
1. Header menu->click on #tab2 link
2. Load page-> scroll to anchor tag-> tab2 is open (this is the part I have a problem with, tab 1 stays open unless I actually click on the tab2 button)
I've tried to change the active class involved, but I'm fairly new to javascript/jquery so I'm not sure I can actually do it; additionally, this is in worpress and the header menu doesn't have the field for an id of its own elements.
===============================
<h1>EDIT, CLARIFICATION: I have the tabs working, and I can go to them on the page from the header link, I just need the right tab to be open depending on the link I click from the header</h1>
I've also tried initiating a .click(#tab2) but the script won't run properly.
Edit:
Header HTML fot link:
Tab HTML
Javascript:
I've gotten the actual tabs to work, using an active class and aria-expanded="true", but I can't get the appropriate tab to be active from the header.
i.e.:
1. Header menu->click on #tab2 link
2. Load page-> scroll to anchor tag-> tab2 is open (this is the part I have a problem with, tab 1 stays open unless I actually click on the tab2 button)
I've tried to change the active class involved, but I'm fairly new to javascript/jquery so I'm not sure I can actually do it; additionally, this is in worpress and the header menu doesn't have the field for an id of its own elements.
===============================
<h1>EDIT, CLARIFICATION: I have the tabs working, and I can go to them on the page from the header link, I just need the right tab to be open depending on the link I click from the header</h1>
I've also tried initiating a .click(#tab2) but the script won't run properly.
Code:
if(window.location.href.indexOf("tab2") > -1) {
document.getElementById('tab2').click();
}
Edit:
Header HTML fot link:
Code:
<ul class="uk-nav uk-nav-navbar">
<li class="uk-active">
<a title="" href="testsite.com/#tab1" >tab 1</a></li>
<li class="uk-active"><a title="" href="testsite.com/#tab2"
class="">tab2</a>
</li>
</ul>
Tab HTML
Code:
<li class="uk-width-medium-1-4 active" id="tab1" aria-expanded="false">
<a class="uk-button tab1">tab1</a>
</li>
<li class="uk-width-medium-1-4 " id="tab2" aria-expanded="false">
<a class="uk-button tab2">tab2</a>
</li>
Javascript:
Code:
var ai = document.getElementById(""); [I'm having trouble with this, cause I can't see a way to attach an id to a wordpress menu item]
var ch = document.getElementById("");
ai.onclick = function(){
document.getElementById('tab1').click();
}
ch.onclick = function(){
document.getElementById('tab2').click();
}