{"id":237,"date":"2011-06-01T14:27:46","date_gmt":"2011-06-01T14:27:46","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=237"},"modified":"2011-06-01T14:27:46","modified_gmt":"2011-06-01T14:27:46","slug":"labels-activate-checkboxes-radio-buttons-jquery","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/labels-activate-checkboxes-radio-buttons-jquery\/","title":{"rendered":"Labels activate checkboxes \/ radio buttons with jQuery"},"content":{"rendered":"<p>The small jQuery snippet below will make those plain old labels that follow checkboxes and radio buttons active. That is, they will activate\/deactivate the checkboxes \/ radio buttons that they follow in the HTML.<\/p>\n<p>As you can see, this will only affect labels that do not already have a <em>for<\/em> attribute.<\/p>\n<p><code>$(&#39;form input:checkbox,form input:radio&#39;).each(function() {<br \/>\n\t&nbsp;&nbsp;&nbsp; if ($(this).next().is(&#39;label&#39;) &amp;&amp; $(this).next().attr(&#39;for&#39;) == &#39;&#39;) {<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(this).next().click(function(){<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(this).prev().click();<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; });<br \/>\n\t&nbsp;&nbsp;&nbsp; }<br \/>\n\t});<\/p>\n<p>\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The small jQuery snippet below will make those plain old labels that follow checkboxes and radio buttons active. That is, they will activate\/deactivate the checkboxes&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[5],"tags":[37],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/237"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":1,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions\/238"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}