Wolphie Posted March 27, 2008 Share Posted March 27, 2008 Ok, so i've created a tabbing system, but i need to add a style to the current tab that it's on. This is my javascript: function initTabs(id) { var parent = document.getElementById("tab_parent"); var elements = document.getElementsByTagName("div"); var aelements = document.getElementsByTagName("a"); var child, anchor; for(var i in elements) { if(elements[i].id == "tab_" + id) child = elements[i]; } for(var i in aelements) { anchor = aelements[i]; anchor.className = (anchor.id == child.id) ? "currentTab" : ""; } if(child != null) parent.innerHTML = child.innerHTML; } This is my HTML: <body> <a href="javascript:initTabs(0);" id="tab_0">Tab 1</a> <a href="javascript:initTabs(1);" id="tab_1">Tab 2</a> <a href="javascript:initTabs(2);" id="tab_2">Tab 3</a> <div id="tab_parent"></div> <div style="display: none;" id="tab_0">Yoooo this is tab 1</div> <div style="display: none;" id="tab_1">Yoooo this is tab 2</div> <div style="display: none;" id="tab_2">Yoooo this is tab 3</div> <script type="text/javascript"> // <![CDATA[ initTabs(0); // ]]> </script> </body> However, the class name is only being added and removed from the 1st anchor tab, rather than being removed from the previous tab and added onto the current tab. Can anybody help? Quote Link to comment https://forums.phpfreaks.com/topic/98223-tabs-current-tab/ Share on other sites More sharing options...
Psycho Posted March 27, 2008 Share Posted March 27, 2008 Well, I took your code and it works for me - after I created a class called "currentTab" Quote Link to comment https://forums.phpfreaks.com/topic/98223-tabs-current-tab/#findComment-502591 Share on other sites More sharing options...
Wolphie Posted March 27, 2008 Author Share Posted March 27, 2008 Yes, it does work. I'm not sure if you have firebug on Firefox, but if you do take a look at the HTML when you're going through the tabs. Quote Link to comment https://forums.phpfreaks.com/topic/98223-tabs-current-tab/#findComment-502611 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.