What if I want to use the for
attribute on an element other than a <label>
? Is this valid HTML? For example:
<div class="feedback" for="my-input-box"></div>
The idea is, I can use JavaScript to get the feedback container for an input using its ID. Like so:
var feedbackContainer = document.querySelector("[for='" + myInputBoxID + "']'");
I just want to know if this is valid HTML or not. If not, I can obviously just go for data-for="..."
instead.