Jabba Da Hoot
Jabba Da Hoot

Reputation: 804

jQuery on change event not triggered by jQuery itself?

I placed a listener on all checkboxes on my page with .on('change'). When clicking on a checkbox it actually detects the change and fires a function. BUT, when I use a jQuery function to set a checkbox to checked like so: $('#checkboxOne').prop('checked', true) the .on('change') doesn't detect a change? How come?

Upvotes: 0

Views: 100

Answers (2)

Kalu Singh Rao
Kalu Singh Rao

Reputation: 1697

If you want to fire jquery function it self, then you should write your function in $(document).ready(function(){ });

Upvotes: 0

daf
daf

Reputation: 1329

Kartikeya Khosla is right

The 'change' event is only fired when a user triggers it. Setting properties from within your own code will not trigger events.

Upvotes: 1

Related Questions