I am working with Bootstrap Cards that have checkboxes inside them. When a checkbox is checked, I want to apply 2 specific classes to the Card DIVs:
- Change class="card border-secondary" to class="card border-success"
- Change class="card-header" to class="card-header text-white bg-success"
The current jQuery code I have in place applies these changes to all the DIVs on the page when a checkbox is checked. However, the toggle functionality for the border class does not work consistently.
I need help refining the jQuery code so that it only applies the changes to the specific div containing the checkbox and ensuring the border class toggle works correctly every time.
$("input[type='checkbox']").change(function() {
if ($(this).is(":checked")) {
$("div.card-header").addClass("text-white bg-success");
$("div.border-secondary").toggleClass("border-success");
} else {
$("div.card-header").removeClass("text-white bg-success");
$("div.border-secondary").toggleClass("border-success");
}
});
.... CSS styles here ....