{"id":473,"date":"2012-03-27T03:26:30","date_gmt":"2012-03-27T03:26:30","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=473"},"modified":"2012-03-27T03:26:30","modified_gmt":"2012-03-27T03:26:30","slug":"jquery-checkbox-checked-or-not-1-line-solution","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-checkbox-checked-or-not-1-line-solution\/","title":{"rendered":"jQuery Checkbox Checked or not: 1 line solution"},"content":{"rendered":"<p>In this article, I am going to present you with 1 line solution to find\u00a0if<em><strong> Checkbox is Checked or not using jQuery<\/strong><\/em>.<\/p>\n<p><!--more--><\/p>\n<h2>How to check if checkbox checked or not using jQuery &#8211; Example<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=473\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>For the sake of example, I am assuming that we have a checkbox with ID &#8220;mycheckbox&#8221;. We wold like to attach different functionality to this checkbox based on whether this checkbox was checked or not. We can do it in the following way:<\/p>\n<h3>Example: Check if checkbox is checked or not using jQuery<\/h3>\n<pre class=\"lang:xhtml decode:true crayon-selected\" title=\"Example: Check if checkbox checked or not using jQuery\">&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Examples to check if a Checkbox is Checked or not using jQuery&lt;\/title&gt;\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.8.2.min.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n\n&lt;input name=\"mycheckbox\" type=\"checkbox\" id=\"mycheckbox\" \/&gt; Check \/ Uncheck this checkbox and click the button below to see the alert\n\n&lt;p&gt;\t\n&lt;input type=\"submit\" name=\"sbt_check\" id=\"sbt_check\" value=\"Check\"&gt;\n&lt;\/p&gt;\n\n&lt;script type=\"text\/javascript\" language=\"javascript\" &gt;\n\n$(document).ready(function(){\n\n\t$('#sbt_check').on(\"click\", function(e){\t\t\t\t\n\n\t\tif( $(\"#mycheckbox\").is(':checked') ) \n\t\t{\n\t\t\talert('Checkbox is checked!');\t\t\t\n\t\t} \n\t\telse \n\t\t{ \n\t\t\talert('Checkbox NOT checked!');\n\t\t}\n\n\t\te.preventDefault();\n\n\t});\t\t\t\t\n\n});\t\n\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<h5><div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=473\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    <\/h5>\n<h5>Your turn!<\/h5>\n<p>Do you know of any other way to <em><strong>find out if a checkbox is checked using jQuery<\/strong><\/em>? Please feel free to share your comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, I am going to present you with 1 line solution to find\u00a0if Checkbox is Checked or not using jQuery.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[41],"class_list":["post-473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-7D","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}