{"id":86,"date":"2009-09-09T23:39:07","date_gmt":"2009-09-09T23:39:07","guid":{"rendered":"http:\/\/localhost\/tfcom_wp\/2009\/09\/09\/jquery-checkall-checkbox\/"},"modified":"2009-09-09T23:39:07","modified_gmt":"2009-09-09T23:39:07","slug":"jquery-checkall-checkbox","status":"publish","type":"post","link":"https:\/\/www.tech-freaks.com\/java\/code-snippets\/jquery-checkall-checkbox.html","title":{"rendered":"Check All checkbox using Jquery"},"content":{"rendered":"<p>This article explains how Jquery can be used to implement a check all checkbox. On checking this &#8216;check all&#8217; checkbox, all other checkboxes present in the page will be checked and when unchecked all the checkboxes will be unchecked.<\/p>\n<p>The below HTML code provides such an example:<\/p>\n<pre class=\"language-markup\"><code>&lt;html&gt;\r\n &lt;head&gt;\r\n  &lt;script type=\"text\/javascript\" src=\"static\/jquery-1.3.1.js\"&gt;&lt;\/script&gt;\r\n  &lt;script type=\"text\/javascript\"&gt;\r\n   \/\/Gets called after the page is completely loaded\r\n   $(document).ready( function() {\r\n    \/\/Get the click event of id checkAll\r\n    $('input#checkAll').click(function(){\r\n     \/\/Get the state of checkAll button.\r\n     \/\/We will use it later to assign it to all other checkboxes\r\n     \/\/See this currently points to checkAll element\r\n     var checkAllState = this.checked;\r\n     \/\/Fetch all checkboxes\r\n     $('input:checkbox').each(function() {\r\n      \/\/this now points to each checkbox iterated\r\n      this.checked = checkAllState;\r\n     });\r\n    });\r\n   });\r\n  &lt;\/script&gt;\r\n &lt;\/head&gt;\r\n &lt;body&gt;\r\n  &lt;div&gt;&lt;h2&gt;Check All Check Box&lt;\/h2&gt;&lt;\/div&gt;\r\n  &lt;div&gt;&lt;input type=\"checkbox\" id=\"checkAll\" name=\"checkAll\"\/&gt;&amp;nbsp;&lt;b&gt;(Un)Check All Color&lt;\/b&gt;&lt;\/div&gt;\r\n  &lt;div&gt;&lt;input type=\"checkbox\" name=\"yellow\"\/&gt;&amp;nbsp;Yellow&lt;\/div&gt;\r\n  &lt;div&gt;&lt;input type=\"checkbox\" name=\"green\"\/&gt;&amp;nbsp;Green&lt;\/div&gt;\r\n  &lt;div&gt;&lt;input type=\"checkbox\" name=\"red\"\/&gt;&amp;nbsp;Red&lt;\/div&gt;\r\n  &lt;div&gt;&lt;input type=\"checkbox\" name=\"blue\"\/&gt;&amp;nbsp;Blue&lt;\/div&gt;\r\n  &lt;div&gt;&lt;input type=\"checkbox\" name=\"pink\"\/&gt;&amp;nbsp;Pink&lt;\/div&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>In the javascript section, comments are provided in line explaining the code.<\/p>\n<p>Save the above code as a HTML including the Jquery lib in correct path and see the above code in action.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article explains how Jquery can be used to implement a check all checkbox. On checking this &#8216;check all&#8217; checkbox, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[13],"tags":[],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-code-snippets"],"_links":{"self":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":0,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}