Set $ .prop () without triggering change
<li> <input type="checkbox" id="master" /> <ul> <li> <input type="checkbox" /> $('input').bind('change', function() {}); // exists elsewhere, cannot change When I click on the top level input, I want to set .prop('checked', true) for all my children, but I want to avoid triggering a change event for each child.
How could I set .prop('checked', true) to enter without running change ?
Edit: (extension)
$('#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 }); }); +8
tester
source share3 answers
What you describe is the default functionality. Changing an element from javascript does not fire the change event.
Note that if you click on the check box in this example, you will receive a warning, but if you click on the button, there will be no warning.
+19
James montagne
source shareYour selector now targets all input elements. You can specify your main flag "Identifier", and the rest - a common class.
<li> <input id="main-chk"type="checkbox" /> <ul> <li> <input class="children" type="checkbox" /> $('li:first').bind('change', function() { $(this).find('li').prop('checked', 'checked'); }); // exists elsewhere, cannot change +1
Jack
source sharetry to untie the onchange listener and then tie it again as soon as the property is set.
0
Drew dahlman
source share