0

Anyone ever seen anything like this before? It's driving me mad! Basically, I've got a checkbox:

<input type='checkbox' id='eventRepeat' />

...and some jQuery, which I've now stripped down to:

$('#eventRepeat').click( function() { alert($(this).attr('checked')) })

...but it alerts 'checked' whether it is checked or not when I click it! Weird. I've checked the DOM to see if there is another rogue eventRepeat; element, but there isn't, and the HTML validates, give or take a warning or two (no errors)

Other checkboxes on the same page work fine! All ideas welcome!

1
  • Cheers - both of those work. Now, where am I using 'attr' in all my code :-( Commented Nov 14, 2011 at 17:22

3 Answers 3

1

You could try -

$('#eventRepeat').click( function() { alert($(this).prop('checked')) })

prop should give a truer representation of the state of the checkbox than the attr function. See the docs - http://api.jquery.com/prop/

Sign up to request clarification or add additional context in comments.

Comments

1

Try using the :checked selector:

$('#eventRepeat').click( function(){ 
    alert($(this).is(":checked")) 
});

Here's a jsFiddle: http://jsfiddle.net/2Es6Z/

Comments

0

Try this http://jsfiddle.net/UGPyT/ it seems to work ^^

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.