I want to add the class to the associated span on checkbox checked with the following code. actually I wants to add the "text-decoration-line", "line-through" to the associated the checkbox span.
But now when I am click on first checkbox css applies to all spans as shown in code.
$(document).ready(function() {
$('input[type=checkbox]').change(function() {
if (this.checked) {
$(".label-text").css("text-decoration-line", "line-through");
} else {
$(".label-text").css("text-decoration-line", "none");
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="p-3 bg-white">
<div class="d-flex align-items-center">
<label>
<input type="checkbox" class="option-input radio">
<span class="label-text">Task list and assignments</span>
</label>
</div>
<div class="d-flex align-items-center">
<label>
<input type="checkbox" class="option-input radio">
<span class="label-text">Set due date and assignments</span>
</label>
</div>
<div class="d-flex align-items-center">
<label>
<input type="checkbox" class="option-input radio">
<span class="label-text">Remove duplicate tasks and stories</span>
</label>
</div>
<div class="d-flex align-items-center">
<label>
<input type="checkbox" class="option-input radio">
<span class="label-text">Update the userflow and stories</span>
</label>
</div>
<div class="d-flex align-items-center">
<label>
<input type="checkbox" class="option-input radio">
<span class="label-text">Adjust the components</span>
</label>
</div>
</div>