-4

$('.p_check').click(function() {
          if ($(this).is(':checked')) {
              alert("checked");
          } else {
               alert("unchecked");
          }
       });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class='checkbox p_check'><label><input type='checkbox'>New Password</label></div>

My alert is always "unchecked", no matter if I check or uncheck it

peace_love
  • 6,229
  • 11
  • 69
  • 157
  • 3
    `$('.p_check')` is a `
    `. Why would you expect that to be checked?
    – charlietfl Nov 23 '18 at 15:21
  • 1
    Also once you fix your incorrect selector, you don't have to do `$(this).is(':checked')` Just use `this.checked` and avoid jQuery for that property access – Taplar Nov 23 '18 at 15:23

1 Answers1

1

You are using div as element for checking, but you should use checkbox:

$('.p_check').click(function() {
var cb =    $(this).find('input[type="checkbox"]');
          if (cb.is(':checked')) {
              alert("checked");
          } else {
               alert("unchecked");
          }
       });
dganenco
  • 1,596
  • 1
  • 5
  • 16