I have a few input
s that have a label
above them. I want to find the closest label
for each of them. The issue is some of the input
s don't have a direct label
above them.
Initially I had this:
let el = document.querySelector(`label[for="${this.element.id}"]`)
This worked for all case except some rare cases where I had two input
s in one line, like test
and test2
. How can I get the test
label
for the test2
input
?
<div>
<label for="test">Interval</label><br>
<input min="0.1" id="test" placeholder="Min" step="0.1" type="number">
<input min="0.1" id="test2" placeholder="Max" step="0.1" type="number">
<label for="limit">Limit</label><br>
<input id="limit" step="1" type="number">
</div>