views:

35

answers:

2

I'm trying to use jQuery .button() on a checkbox, but i can't understand why this is'not working.

this is the javascript code:

$('#login_checkbox').button();

and this is the html code:

<input id="login_checkbox" type="checkbox" value="login_remember"/><label>Remember me</label>

I'm doing everything exacly as shown here: http://jqueryui.com/demos/button/#checkbox

+1  A: 

Is that code running in a "ready" handler, or just naked in a <script> block in the head of your page?

In other words, are you sure that the element exists at the time the Javascript code runs? That's a really easy mistake to make, especially when throwing together little proofs-of-concept.

Pointy
The JS code is inserted along with other working lines: $(function() { $('#tac').hide(); $('#username_error').hide(); $('#password_error').hide(); $('#email_error').hide(); $('#login_checkbox').button(); $('#login_choice_container').buttonset(); }); .The only thing not working is $('#login_checkbox').button(); :S
Silvio Iannone
OK then check @Hogan's answer!
Pointy
+1  A: 

Add in the for attribute or it won't know which label to use:

<label for="login_checkbox">Remember me</label>
Hogan
ooo yes that's a good point!
Pointy
Thank you Hogan! You save me an headache! I hate those kinds of mistakes!
Silvio Iannone
@Silvio accept his answer to make me feel a little less cheap for guessing at something that wasn't your actual problem :-)
Pointy
Sorry if i accepted later, but i hade to wait 4 minutes.
Silvio Iannone
@Pointy thanks for your support :D
Hogan