Tabbed Content / Posts /

Identify which tab is active

22
I have some common controls in the div class "tabcontents", before the first tab , div "view1", is defined.  One such control is a button, which when clicked needs to know which tab is active.  Can this be done?
Thanks for sharing this awesome code and solution!
Fred



Fred  11 years ago   viewed: 12763    

3 Answers

0
You need programming with JavaScript based on checking the className of the tabs. For example:

var lis = document.getElementById("theULid").getElementsByTagName("li");
for(var i=0; i<lis; i++){
if(lis[i].className == "selected")
return i; //or return lis[i], or return lis[i].getElementsByTagName("a")[0]
}
Joe   11 years ago
3
Thanks Joe!
  While I don't know much about JavaScript, you did put me on the right path to discovery!  Sad to say, I'm limited to writing in VB script, and I had to take steps to get your routine into a VB script equivalent!
        Set LI = document.getElementById("Allofthetabs").getElementsByTagName("li") : iCount = 0
For Each LIItem IN LI
iCount = iCount + 1 : if LIItem.ClassName = "selected" then Exit For
Next
 
When the above loop exists, iCount holds the number of the selected tab..., which is to say, exactly what I needed!
Thanks again for your code and example!

Fred
Fred   11 years ago
0

The advanced version, jQuery Tabs, has an event handler onTabSelected. The first parameter passed to the onTabSelected function is the clicked tab. So you can get the clicked tab there. For details please read the http://www.menucool.com/jquery-tabs#Div3

Milo   9 years ago

   

Your name*
Password
(Optional. Used to modify this post afterwords)
+ =  

Ask your Own Question

  • If your question is related to the topic of this post, you can post your question to this page by clicking the "Post a reply" button at left;

  • When you want to start a new page for your question: