Question: I have this JavaScript code:

```
$(document).ready(function(){
    $('#CustomersResellers').hide();

    $('input.ShowResellerAccounts').on('click', function(){
        if($(this).is(':checked')){
            alert('checked');
        }
    });
});

```

which shows the alert when I check the box, but if the box is already checked on page load, it does not show the alert.

Answer: 
Lets update the function:

```
var alertChecked = function() {
  if($(this).is(':checked')){
    alert('checked');
  }
}

// invoke the function when clicked
$('input.ShowResellerAccounts').on('click', alertChecked); 

//invoke the function for all matching elements
$('input.ShowResellerAccounts').each(alertChecked); 

```
This is exactly the behavior I would expect. 
`if $(this).is(':checked')` means 'if this checkbox is checked' - then show the alert. But when you click to uncheck the box (`on('click'...)`), it becomes unchecked and alert does not show.