{"id":106,"date":"2015-07-29T02:18:00","date_gmt":"2015-07-29T02:18:00","guid":{"rendered":"http:\/\/waynenguyen.org\/dev\/2015\/07\/29\/how-to-check-if-checkbox-is-checked\/"},"modified":"2016-05-21T03:15:55","modified_gmt":"2016-05-21T03:15:55","slug":"how-to-check-if-checkbox-is-checked","status":"publish","type":"post","link":"https:\/\/bruceng.com\/dev\/?p=106","title":{"rendered":"How to check if a checkbox is checked using jQuery and set\/unset it programmatically"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\">\nLet&#8217;s say you have a checkbox like the following<\/p>\n<p>&lt;input type=&#8221;checkbox&#8221; id=&#8221;leCheckBox&#8221;&gt;<\/p>\n<p>To check if it&#8217;s checked or not, use:<\/p>\n<p>var leCheckBoxIsChecked = $(&#8220;#leCheckBox:checked&#8221;).length&gt;0;<\/p>\n<p>It will returns true if the checkbox is checked and false otherwise.<\/p>\n<p>\nTo check the checkbox programmatically:<\/p>\n<p>$(&#8220;#leCheckBox&#8221;).prop(&#8220;checked&#8221;, &#8220;true&#8221;);<\/p>\n<p>\nTo uncheck the checkbox programmatically:<\/p>\n<p>$(&#8220;#leCheckBox&#8221;).removeAttr(&#8220;checked&#8221;)<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you have a checkbox like the following &lt;input type=&#8221;checkbox&#8221; id=&#8221;leCheckBox&#8221;&gt; To check if it&#8217;s checked or not, use: var leCheckBoxIsChecked = $(&#8220;#leCheckBox:checked&#8221;).length&gt;0; It will returns true if the checkbox is checked and false otherwise. To check the checkbox programmatically: $(&#8220;#leCheckBox&#8221;).prop(&#8220;checked&#8221;, &#8220;true&#8221;); To uncheck the checkbox programmatically: $(&#8220;#leCheckBox&#8221;).removeAttr(&#8220;checked&#8221;)<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-106","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=106"}],"version-history":[{"count":1,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/106\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/106\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}