On the website im building, each tab has a class on its li of either tab1, tab2, tab3 etc
What I want to do is first check to see if a tab has a class of "cur" then if it does, check the rest of the li to see if it has another class of either "tab1", "tab2", "tab3", "tab4" or "tab5" then add that "tab" class to the body tag
to get get something like this
<body class="tab2">
<div class="nav">
<ul>
<li class="current1 tab1">First Tab</li>
<li class="current1 cur sub tab2">Second Tab</li>
<li class="current1 sub tab3">Third Tab</li>
<li class="current1 sub tab4">Fouth Tab</li>
<li class="current1 sub tab5">Fifth Tab</li>
</ul></div>
i've tried something like the jQuery below but it always adds an additional class of tab5 to the body as well
if ( $('.navigation ul li.tab1').hasClass('cur') ) {
$('body').addClass('tab1');
} else if ( $('.navigation ul li.tab2').hasClass('cur') ) {
$('body').addClass('tab2');
} else if ( $('.navigation ul li.tab3').hasClass('cur') ) {
$('body').addClass('tab3');
} else if ( $('.navigation ul li.tab4').hasClass('cur') ) {
$('body').addClass('tab4');
} else ( $('.navigation ul li.tab5').hasClass('cur') ); {
$('body').addClass('tab5');
}
I know there is a much cleaner way of doing it but can't seem to work it out
I wish I could just add the class manually, but i dont have access to the HTML so have to generate it with javaScript
Any help much appreicated
Thanks