wong2
wong2

Reputation: 35760

How to make the checkbox selected when click the label?

<input type="checkbox"  />  
<label>I agree</label>  

Now when I click "I agree", nothing happens, I'd like to make the checkbox checked, what's the easiest way to do this?

Upvotes: 5

Views: 4834

Answers (2)

Dan F
Dan F

Reputation: 12051

As an alternative to what @stevether suggested, you can also wrap the label around the checkbox

<label><input type="checkbox"  /> I agree</label> 

http://jsfiddle.net/WDerc/

Upvotes: 4

Steve Robbins
Steve Robbins

Reputation: 13822

for and id attributes

<input id="thisinput" type="checkbox"  />  
<label for="thisinput">I agree</label>

http://jsfiddle.net/PNYNR/

Upvotes: 10

Related Questions