Always use the for attribute on labels

In the same vein as the last post: For a while there, I thought I could take a shortcut by saying:



<label><input type="checkbox" name="foo" value="1" /> The label</label>


Instead of the more cumbersome:



<label for="mycheckbox"><input type="checkbox" name="foo" id="mycheckbox" value="1" /> The label</label>


That way I don’t have to worry about setting the ID for the checkbox, making sure it’s unique, and all that.



It works fine in Firefox, and Safari ignores it, just like it ignores any old label tag. But Internet Explorer, of course, had to not work. So forget about that, and just use the for and id attributes like you always did. Bah.

0 comments

There are no comments yet. Be the first one to leave a comment!

Leave a comment