How to change the value of a check box onClick using JQuery?

With this code, you can change the value of the check box to 1 when it is checked, or to 0 when it is unchecked:


<input type="checkbox" id="read" onClick="" />
  1. You should do this:
    onclick="$(this).attr('value', this.checked ? 1 : 0)"
  2. Or even:
    onclick="$(this).val(this.checked ? 1 : 0)"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s