0

I am trying to select a radio button by clicking on text next to radio button. How can I enable click on radio button text to select radio button?

What I tried is here

<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female

Edit: I am sorry. I found answer here

Community
  • 1
  • 1
Kurkula
  • 6,945
  • 26
  • 108
  • 186
  • A JS library which does this well http://www.onextrapixel.com/2014/01/07/label-your-input-fields-like-a-boss-with-label_better-js/ – Amar H-V Feb 01 '14 at 01:53

1 Answers1

2

You would use a label element and match the for attribute with the id of the input:

UPDATED EXAMPLE HERE

<input type="radio" name="sex" id="male" value="male"/>
<label for="male">Male</label>

<input type="radio" name="sex" id="female" value="female"/>
<label for="female">Female</label>
Josh Crozier
  • 219,308
  • 53
  • 366
  • 287