Reputation: 3250
I would like to understand.
Why this will not work:
$(this).closest("li").find("ul:checkbox").prop("checked", true);
But this will?
$(this).closest("li").find("ul").find(":checkbox").prop("checked", true);
Thanks
Upvotes: 2
Views: 1705
Reputation: 337656
The issue in your first example is because of ul:checkbox
. This looks for <ul>
elements which are also checkboxes, which is not possible. You need a space between those selectors, or to use find()
as you are in the second example.
Either of these will work:
$(this).closest("li").find("ul :checkbox").prop("checked", true);
// or
$(this).closest("li").find("ul").find(":checkbox").prop("checked", true);
Upvotes: 7