Reputation: 8970
I am using bootstrap tabs in my application and on change of a dropdown, i want to find out what tab is currently active and from that, get an attribute from the active tab.
So far I have this: $("ul#depts li.active").text();
which gets me the text of the active tab.
However, when I try something like ("ul#depts li.active").attr('departmentid')
nothing is returned.
<ul id="depts" role="tablist" class="nav nav-tabs">
<li class=""><a data-toggle="tab" role="tab" href="#Disputes" departmentid="2" name="switchDepartment" class="switch">Disputes</a></li>
<li class="active"><a data-toggle="tab" role="tab" href="#ICA" departmentid="5" name="switchDepartment" class="switch">ICA</a></li>
</ul>
What am I missing?
Upvotes: 0
Views: 83
Reputation: 4682
Two basic corrections:
Your're missing $
sign in: ("ul#depts li.active").attr('departmentid')
Deptid is attribute of <a>
element inside that li
so it'll be
$("ul#depts li.active a").attr('departmentid')
Upvotes: 1
Reputation: 100175
as per your posted HTML, you have set attribute in anchor tag not in li, so change to:
("ul#depts li.active > a").attr('departmentid');
Upvotes: 3