Here is the code I am currently working with:
<div class="form-control-switch-option">
<input type="radio" data-value="Buy">
<label class="form-control-switch-option-label text-color__dark btns-family">For Sale</label>
</div>
<div class="form-control-switch-option">
<input type="radio" data-value="Buy" checked="checked">
<label class="form-control-switch-option-label text-color__dark btns-family">For Sale</label>
</div>
I would like to add the class "working
" to the parent element (form-control-switch-option
) when the input
element is checked
. So, in the example above, it should look like this:
<div class="form-control-switch-option">
<input type="radio" data-value="Buy">
<label class="form-control-switch-option-label text-color__dark btns-family">For Sale</label>
</div>
<div class="form-control-switch-option working">
<input type="radio" data-value="Buy" checked="checked">
<label class="form-control-switch-option-label text-color__dark btns-family">For Sale</label>
</div>
Is there a way to achieve this using only vanilla JavaScript (no jQuery)?