I want to get the id of the id of the element which has class active. I've viewed this thread , but isnt able to get the o/p I want.
<ul class="nav nav-pills nav-stacked navigation" id="configuration_sidebar_content">
<li>
<a>Location</a>
<ul class="nav nav-pills nav-stacked " id="location" style="padding-left:30px;">
<li class="active" id="region"><a>Region</a></li>
<li id="country"><a>Country</a></li>
</ul>
</li>
<li>
<a>Device</a>
<ul class="nav nav-pills nav-stacked" style="padding-left:30px;">
<li id="gateway_unit"><a>Gateway Unit</a></li>
<li id="meter_unit"><a>Meter Unit</a></li>
</ul>
</li>
</ul>
I tried this.
selected_item_id = $("#configuration_sidebar_content li.a.active").attr('id')
The class ID is a unique number that is automatically generated upon the creation of a class. You can find this on your instructor homepage, under the column 'Class ID', right next to the class name.
The jQuery hasClass() method is used to check whether selected elements have specified class name or not. It returns TRUE if the specified class is present in any of the selected elements otherwise it returns FALSE. Syntax: $(selector).
In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.
it should be
$("#configuration_sidebar_content li.active").attr('id')
there is no class a
assigned to the li
element, a
is a child element of the li
element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With