7

The standard HTML 5 form label wants an ID to link the label to the input.

<form>
  <label for="male">Male</label>
  <input type="radio" id="male"/>
  <label for="female">Female</label>
  <input type="radio" id="female"/>
</form>

As most JS developers know, using IDs leaks globals - in this case, window.male and window.female are created.

How can I use form labels without creating globals?

Community
  • 1
  • 1
mikemaccana
  • 110,530
  • 99
  • 389
  • 494

1 Answers1

10

use the other way:

<form>
    <label>Male <input type="radio"></label>    
    <label>Female <input type="radio"></label>    
</form>
Dziad Borowy
  • 12,368
  • 4
  • 41
  • 53