<li>
<input type="checkbox" id="master" />
<ul>
<li>
<input type="checkbox" />
$('input').bind('change', function() {}); // exists elsewhere, cannot change
When I click the top level input, I want to set .prop('checked', true)
for all of its children, but I want to avoid triggering the change
event for each child checkbox.
How could I set .prop('checked', true)
to an input without triggering change
?
Edit: (expanding)
$('#master').click(function() {
$(this).parent().find('input').each(function(n, in) {
$(in).prop('checked', true); // this triggers a change event that I need to stop
});
});
try to unbind the onchange listener, then bind it again once the property has been set.
What you are describing is the default functionality. Changing an element from javascript does not fire the change event.
http://jsfiddle.net/8JsP4/
Notice how if you click on a checkbox in the example, you get an alert, but if you click the button, no alert.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With