When A Label Only Has A Button, A Button Click Does Not (fully?) Trigger The Label
Solution 1:
A
label
can only be associated with one form control at a time. This is evidenced by the fact that thefor
attribute points to an element with a matching ID attribute.You have a
button
that is a descendant of yourlabel
; the expected interpretation of this is that thelabel
serves as a label for thebutton
. However, you're trying to associate the radio button, not thebutton
element, with thelabel
. The real problem here is that there is a conflict between the form controls and thelabel
; it's unable to figure out which control it's supposed to be associated to.I'm guessing that the fact the radio button isn't working correctly is a side effect of this. Perhaps it's down to some activation behavior in both the radio button and the
button
element.I've checked that
button
s are legal children oflabel
s. Labels allow Phrasing Content, and buttons are Phrasing Content, so everything should be okay there.The validator does nevertheless produce the following error with your markup:
Error: Any
button
descendant of alabel
element with afor
attribute must have an ID value that matches thatfor
attribute.This is because a
label
element with afor
attribute needs to have a form control with that ID value for thefor
attribute to point to, even if that control is a descendant of thelabel
itself. But you can't assign the same ID to more than one element. The result is the aforementioned conflict.Without knowing what you're trying to accomplish here, the best advice I can give if you just want the
label
to have the appearance of a button is to just style it as such.
Post a Comment for "When A Label Only Has A Button, A Button Click Does Not (fully?) Trigger The Label"