Looking to dynamically add a class to the label element when focusing on an input element below it. The current HTML and JS code I'm using is as follows:
HTML:
<label for="formProductId" ref="productIdLabel" class="form-element-title">Product ID</label>
<input id="formProductId" @blur="toggleFocus('productIdLabel', false)" @focus="toggleFocus('productIdLabel', true)" v-model="filterValues.productId" :name="filterOptions.productId === true ? 'productId' : false" type="text">
JS:
toggleFocus(ref: string, enable: boolean) {
if (enable) {
(this.$refs[ref] as HTMLElement).classList.add("js-focused");
} else {
(this.$refs[ref] as HTMLElement).classList.remove("js-focused");
}
}
Wanting to enhance this functionality by removing the ref attribute and toggling the js-focused class directly from the selected element. Any ideas on how to select the closest label element and modify its class?