I have divs that contain 1 checkbox within it. Whenever I click the div, it will change the class name of the div. Additionally, I want to check & uncheck the tags while changing the class name of the div.
$(".tags").click(function() {
if ($(this).hasClass("active")) {
$(this).removeClass("active");
$(this).addClass("inactive");
} else if ($(this).hasClass("inactive")) {
$(this).removeClass("inactive");
$(this).addClass("active");
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
.active{
color: green;
}
.inactive{
color: red;
}
</style>
<div class="tags active" name="item1"> Item1 <input type="checkbox" name="item1"></div>
<div class="tags active" name="item2"> Item2 <input type="checkbox" name="item2"></div>
<div class="tags active" name="item3"> Item3 <input type="checkbox" name="item3"></div>
How do I find a checkbox inside it each div and check/uncheck will clicking on the div?