javascriptjquerynextuntil

nextUntil() and childElements


the elements:

<div><input type="checkbox"></input></div> // <-- checked
<div><input type="checkbox"></input></div> // <-- checked
<div><input type="checkbox"></input></div> // <-- unckecked
<div><input type="checkbox"></input></div> // <-- checked

I want to use nextUntil() with the div-elemets to uncheck the boxes(child-elements) until box3 (first unchecked). Is there a way?


Solution

  • The checkboxes being in different containers makes this rather complicated. The checkboxes in your example are NOT siblings to each other, which is why nextUntil (or rather prevUntil ) wont work here.

    $("input:checkbox:not(:checked)").parent().prevAll("div").find("input:checkbox").prop("checked", false);
    

    That is assuming its not always the same checkbox that is checked.