Toggle a checkbox using jQuery

PostJan 30th, 2010 | Comments (0)
If you're using jQuery and you need to toggle a checkbox, add this onclick code to an object:

onclick="$('#id_of_checkbox').attr('checked',!$('#id_of_checkbox').attr('checked'));"

The above code sets the "checked" attribute of the checkbox to the opposite of itself, i.e. checked -> unchecked or unchecked -> checked.

Comments

There have been no comments

Post a comment

Name
URL
Email
Comment