Is it possible with Jquery to add another class to the .body element when the third li element has an .active class? It cant just add an class based on the .active class, it has to be the .active on the third li element specifically.
<div id="extendedinfobox">
<ul class="prodtabmenu">
<li></li>
<li></li>
<li class="active"></li>
<li></li>
<li></li>
</ul>
</div>
<div class="body">
https://jsfiddle.net/sn2nc9bd/1/
if($('ul.prodtabmenu').find('li:nth-child(3)').hasClass('active'))
{
$('.body').addClass('newClass');
}
if ($('ul.prodtabmenu').find('li:nth-child(3)').hasClass('active')) {
//$('body').addClass('disabled');
$('.body').addClass('disabled');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div id="extendedinfobox">
<ul class="prodtabmenu">
<li>2</li>
<li>21</li>
<li class="active">3</li>
<li>4</li>
<li>1</li>
</ul>
</div>
<div class="body">
Try like this
Use .nth-child()
Description: Selects all elements that are the nth-child of their parent.
use .nth-child(3) to select the 3rd li
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