Raccoon Raccoon - 1 year ago 56
Javascript Question

Select all checkbox except the last of a specific element

I want to check if all checkbox of a specific element are checked BUT the last one
I have this kind of HTML

<ul class="progress-indicator">
//Others elements (variable)
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox"> // Exclude this one
//Stuff here
//Another stuff

I firstly tried that

if($(".progress-indicator > li:first-child").find(":checkbox").length == $(".progress-indicator > li:first-child").find(":checkbox:checked").length)
//All checkbox of first li are checked

This is working but now I want to exclude the last checkbox of the first

So I started with that

$(".progress-indicator > li:first-child").find(":checkbox:not(:last-child)").length

But it did not work. This selector select only the first checkbox of the first
. I think it due to the
Others elements
that I have before. (The checkbox are by exemple inside a
which is inside another element.

So, how to select all the checkbox of the first
except the last checkbox OF this

Answer Source


$(".progress-indicator >li >input[type='checkbox']:not(:last)").prop("checked", true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download