Check if a class active
exist on an li
with a class menu
For example
<li class="menu active">something...</li>
jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".
The hasClass() is an inbuilt method in jQuery which check whether the elements with the specified class name exists or not. Syntax: $(selector). hasClass(className);
I think you want to use hasClass()
$('li.menu').hasClass('active');
You can retrieve all elements having the 'active' class using the following:
$('.active')
Checking wether or not there are any would, i belief, be with
if($('.active').length > 0) { // code }
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