[Vuejs]-Vue2 add class to focused input

-1👍

First of all you’re not being very clear what you want to do.
2nd of all you have found solution so just clean up your code.
3rd of all I’d try using el.closest.

const input = document.getElementById('yourInput');
const label = input.closest("label");
// or if you want to add ids to labels
const label2 = input.closest("#yourLabel");

Link to docs

With this solution you will be little bit more save. Couse in yours, lets just imagine that somebody change HTML structure… Then very high risk your code stops working.

Leave a comment