jQuery return position of list element with class on table column click -
I was wondering how to return the status of a list element with a class of 'currentTab' in the following undetined list :
& lt; Ul id = "coverTabs" & gt; & Lt; Li class = "current tab" & gt; & Lt; A href = "#" & gt; Individual & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Couple & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Family & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Single parent family & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;
The class is set to be set to HTML. The following clicks sets the tab to 'currentTab' and then removes the previous square:
$ ('ul # covertabs & gt; li'). Live ('click', function) Adds the 'Current Tab' category $ ("CurrentTab"), which removes the default class applied in the clickable tab // html and onclicks. RemoveClass ("currentTab"); $ (This) .addClass ("currentTab");});
I thought that if I added the following in the above, then it will return the status of the tab which is currently running:
// Search Active Pause tab var tab = $ ('ul # coverTabs & gt; li.currentTab'). Index ($ (. CurrentTab ')); Var tab.position = tabPosition + 1
This does not work for me.
Use this
keyword when referencing an existing item. < / P>
var tabPosition = $ ('ul # coverTabs & gt; li') index ($ (this)); However the problem in your case was that you were limiting the index inside the current tab, so you were just selecting one .. < Code> var tabPosition = $ ('ul # covered tabs & gt; li'). Index ($ (. CurrentTab '));
The above should also work (note that I have removed .currentTab
from the selector first)
Comments
Post a Comment