I know that it is good sometimes to associate a label with a checkbox:
<input id="something" type="checkbox" value="somevalue" /> <label for="something">this is label text</label>
..but do I have to use an id to associate it?
The main reason I even care is because I like being able to click a label to toggle the checkbox value, but don't like the idea of using an id for something so simple.
I guess I could use jQuery toggle the previous element (checkbox) of a clicked label, but maybe there is something simpler I'm missing. https://stackoverflow.com/a/2720771/923817 looked like a solution, but the user said it doesn't work in IE.
The ID on your checkbox is necessary because the ID field is what the label's for attribute references, and you need a relationship between the label and the checkbox as I previously mentioned. Show activity on this post. Certain fields are inherently unique; names, id's and label names.
All you have to do is use a "br" tag after each ending "label" tag. In other words, by using the "br" or break tag, you're telling the checkbox to "break" down to the next line that is available. Hope that helps!
Without label tags, users can't click the label to tick the checkbox. Instead, they have to click the checkbox itself. This causes users to struggle because the checkbox is a small target to hit especially for motor-impaired users.
Yes, place the input inside the label.
<label><input type=checkbox name=chkbx1> Label here</label>
See implicit label association in the HTML specifications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With