Tick checkbox using jQuery


Checkboxes work a bit different, they have a value, but it's not what you have to set if you want to tick / enable a checkbox.


We've got a simple structure like this:

<input type="checkbox" id="myCheckbox">

If you then want to tick the checkbox using jQuery, you simply have to run this code:

$("#myCheckbox").prop("checked", true)

Set the second parameter to false to undo this. Please note that you'll find a lot of different approaches on the internet. That's mostly because there was a change in jQuery 1.6, but since that's already an ancient version, we are not going to cover that here.


Please sign-in to post a comment