Jquery Check parent checkboxes in nested ul li

后端 未结 5 1929
情话喂你
情话喂你 2021-01-02 12:48

I have a script that will check and uncheck all children checkboxes in a nested list. I am now trying to get it so I can check a low level checkbox and it will check all the

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 13:14

    Just use jquery.parents(). It is somewhat similar to find() except it searches all parents. Something like this might be close to what you are looking for:

    $(this).parents('li').each(function() {
      $(this).children('input').prop('checked', true);
    });
    

    See http://api.jquery.com/parents/ for more information.

    EDIT: Alright, here is a solution that works:

    http://jsfiddle.net/3y3Pb/12/

    EDIT2: And a more streamlined solution here:

    http://jsfiddle.net/3y3Pb/14/

提交回复
热议问题