Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use HTML5 form labels without leaking globals?

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?

like image 635
mikemaccana Avatar asked Dec 20 '13 12:12

mikemaccana


1 Answers

use the other way:

<form>
    <label>Male <input type="radio"></label>    
    <label>Female <input type="radio"></label>    
</form>
like image 157
Dziad Borowy Avatar answered Sep 23 '22 23:09

Dziad Borowy