Posted by & filed under Code Tips.

Quick little snippet to toggle the value of a checkbox with jQuery.

jQuery('#checkbox_id').prop('checked', !jQuery('#checkbox_id').prop('checked'));

I needed this a couple days ago using a span with a font awesome image to take the place of a checkbox. Still needed an actual checkbox underneath for the form handler to work with. So I used this little piece of code to toggle the state of a hidden checkbox and then used the state of that checkbox to determine what CSS class to use for the fake checkbox.

Leave a Reply

Your email address will not be published. Required fields are marked *