• $('input').bind('change', ...">
    Geek Answers Handbook

    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
    jquery
    tester Feb 03 '12 at 21:50
    source share
    3 answers

    What you describe is the default functionality. Changing an element from javascript does not fire the change event.

    http://jsfiddle.net/8JsP4/

    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 Feb 03 '12 at 21:54
    source share

    Your 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 Feb 03 '12 at 21:57
    source share

    try to untie the onchange listener and then tie it again as soon as the property is set.

    0
    Drew dahlman Feb 03 '12 at 21:53
    source share

    More articles:

    • The expression > from the F # function - linq
    • Using read without starting a newline on a terminal - bash
    • How to combine two arrays of JSON objects - removing duplicates and maintaining order in Javascript / jQuery? - json
    • MonkeyRunner: an easy way to determine the coordinates for a MonkeyDevice touch command? - android
    • Hive / HBase integration - Zookeeper session closes immediately - hbase
    • Unwanted loading in EntityFramework with DbContext.Database.SqlQuery - tsql
    • Python edge detection and curvature calculation - python
    • How to pretend by following my finger using onScroll and GestureDetector - Android - android
    • Shape Recognition - Mango Counting - image-processing
    • Image Processing Library for C ++ - c ++

    All Articles

    Geek Answers | 2019