jQuery – Check if a Checkbox is CHECKED

So many “check” in this post title. haha~

You can get the checkbox state by the the following jQuery.

// true if checked
$('#checkbox-id').is(":checked");

 

Try the following HTML.

<html>
  <head>
    <title>jQuery - Check if Checkbox is CHECKED</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        $('#checkbox-id').click(function() {
          alert($('#checkbox-id').is(":checked"));
          // For older version of jQuery 
          //alert($('#checkbox-id').attr('checked'));
        });
      });
    </script>
  </head>
  <body>
    <input id="checkbox-id" type="checkbox" />
  </body>
</html>

 

Done =)

Reference: jQuery: 判斷 checkbox 是否被選取

Advertisement

2 thoughts on “jQuery – Check if a Checkbox is CHECKED”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.