How do i detect a special class in a child div and a when the specific class is found add a class into a other div?
Example:
<ul class="m-a-ul">
<li class="menu">
</ul>
Now the specific class collapsed
is added through an action:
<ul class="m-a-ul">
<li class="menu collapsed">
</ul>
A script should now detect that a child of the ul
m-a-ul
got added a class named collapsed
. Now the class darken
should be added to a other div with the ID content
:
<div id="content" class="darken">
...
</div>
And now, when the class collapsed
disapears the class darken
should also be removed
Ive tried this Code:
<script>
$(document).ready(function(){
$(".menu").click(function(){
$("#content").addClass("darken");
});
});
</script>
That adds the class darken when a button is clicked. But that was the wrong solution. I need one that add the class only when a class is found in a specific div.