7

When I add a label the a form input, I can normally click the label and it will refer me to the appropriate input (see below).

<label for="input">Label</label><input type="text" id="input"/>

However, when I try to accomplish the same with a file input, the click on the label gets ignored. Is this a bug? A "feature"? And is there any way to still accomplish this?

jsFiddle testcase: here

Exelian
  • 5,749
  • 1
  • 30
  • 49

1 Answers1

2

The label's prescribed behavior differs between HTML specifications.

More precisely, this is probably a bug in FF (rather than an extra feature in the others), because this behavior should usually be included according to the HTML 4 spec: When a LABEL element receives focus, it passes the focus on to its associated control. See the section below on access keys for examples.

The current HTML spec is more nuanced, but does indicate the possibility that it do nothing (this is the expected behavior in iOS).

Community
  • 1
  • 1
Eran Zimmerman Gonen
  • 4,375
  • 1
  • 19
  • 31
  • 4
    Just wanted to point out had sad I get when people cite w3schools... let's just say they're not at all credible. Please see http://w3fools.com/ – MusikAnimal Jul 10 '12 at 05:18
  • +1 @MusikAnimal it is just amazing how such an inaccurate source is so popular (at least judging how high they are ranked in google's results) – fortran Oct 30 '12 at 19:09