Question: I want to programmatically check a checkbox and trigger the checkbox's onchange function

I have tried `("#myCheckbox").click()` but it only checks it and does not call its onchange function

How can I get the onchange function to execute as well?

**edit:**

When the document is ready i need the checkbox checked and its on change function called programatically.

Answer: 
Your change listener needs to be set **before** you trigger the click on the checkbox. The following code works with no issues:

```
$("#myCheckbox").on('change', function(){
   console.log('Change'); 
}).click();

```

[JSFiddle](http://jsfiddle.net/x7ZWB/)
you can try like below

```
 $("#scheck").attr('checked', 'checked').change();

```

it will check the check box as well trigger onchange event for checkbox

ex:

Script : 

```
    $(document).ready(function () {
        $("#scheck").attr('checked', 'checked').change();
    });      

    function checkitout() {
        alert("onchange event fired");
    }

```

HTML : 

```
    <input type="checkbox" name="tdcheck" id="scheck" onchange="checkitout();" />

```