{"id":1168,"date":"2012-11-29T23:57:40","date_gmt":"2012-11-29T23:57:40","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1168"},"modified":"2012-11-30T00:46:54","modified_gmt":"2012-11-30T00:46:54","slug":"how-to-select-all-check-boxes-with-one-click","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2012\/11\/how-to-select-all-check-boxes-with-one-click\/","title":{"rendered":"How to select all check boxes with one click ?"},"content":{"rendered":"<p>Selecting multiple items from a list to process them or delete them is just one like of jquery program. <\/p>\n<pre lang=\"php\">\r\n<script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.8.3\/jquery.min.js\"><\/script>\r\n\r\n<fieldset>\r\n    <div><input type=\"checkbox\" class=\"checkall\"> Check all<\/div>\r\n\r\n    <div><input type=\"checkbox\"> Checkbox 1<\/div>\r\n    <div><input type=\"checkbox\"> Checkbox 2<\/div>\r\n    <div><input type=\"checkbox\"> Checkbox 3<\/div>\r\n<\/fieldset>\r\n\r\n\r\n<script>\r\n$(document).ready(function(){\r\n        $('.checkall').click(function () {\r\n            $(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);\r\n        });\r\n});\r\n<\/script>\r\n<\/pre>\n<p>Here is another version which does not use fieldset<\/p>\n<pre lang=\"php\">\r\n    <div><input type=\"checkbox\" class=\"checkall\" id=\"select_all\"> Check all<\/div>\r\n\r\n    <div><input type=\"checkbox\" class=\"case\"> Checkbox 1<\/div>\r\n    <div><input type=\"checkbox\" class=\"case\"> Checkbox 2<\/div>\r\n    <div><input type=\"checkbox\" class=\"case\"> Checkbox 3<\/div>\r\n\r\n\r\n<SCRIPT language=\"javascript\">\r\n$(function(){\r\n \r\n    \/\/ add multiple select \/ deselect functionality\r\n    $(\"#select_all\").click(function () {\r\n          $('.case').attr('checked', this.checked);\r\n    });\r\n \r\n    \/\/ if all checkbox are selected, check the selectall checkbox\r\n    \/\/ and viceversa\r\n    $(\".case\").click(function(){\r\n \r\n        if($(\".case\").length == $(\".case:checked\").length) {\r\n            $(\"#select_all\").attr(\"checked\", \"checked\");\r\n        } else {\r\n            $(\"#select_all\").removeAttr(\"checked\");\r\n        }\r\n \r\n    });\r\n});\r\n<\/SCRIPT>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Selecting multiple items from a list to process them or delete them is just one like of jquery program. Check all Checkbox 1 Checkbox 2 Checkbox 3 Here is another version which does not use fieldset Check all Checkbox 1 Checkbox 2 Checkbox 3<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[30],"tags":[],"class_list":["post-1168","post","type-post","status-publish","format-standard","hentry","category-jquery"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1168"}],"version-history":[{"count":5,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1168\/revisions"}],"predecessor-version":[{"id":1173,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1168\/revisions\/1173"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}