I cant remove or add the class within a div
and trying to remove the class .wew
when the .st-collapse
is visible and add class .wew1
if the .st-collapse
is hidden
so my flow is go to each parent div and find its div child
my HTML
<div class="st">
<div class="st-heading wew">
<a href="#">Link 1</a>
</div>
<div class="st-collapse">
<ul>
<li><a href="#">Sub-Link 1</a></li>
<li><a href="#">Sub-Link 2</a></li>
<li><a href="#">Sub-Link 3</a></li>
</ul>
</div>
</div>
<div class="st">
<div class="st-heading wew">
<a href="#">Link 1</a>
</div>
<div class="st-collapse">
<ul>
<li><a href="#">Sub-Link 1</a></li>
<li><a href="#">Sub-Link 2</a></li>
<li><a href="#">Sub-Link 3</a></li>
</ul>
</div>
</div>
this is my script
jQuery(".st").each(function(){
var s = jQuery(this).find(".st-collapse").is(":visible");
if(s){
jQuery(this).find(".st-heading").removeClass("wew");
}else{
jQuery(this).find(".st-heading").addClass("wew1");
}
});