Tom
Tom

Reputation: 1263

jQuery - Loop through using first and each?

How would I go about looping through the checkboxes that are in the 'tr.acf-row', not in the 'acf-row clone' ? Any help is appreciated! Thanks!

Here's what I have tried:

 jQuery('.field_key-field_54232c5d030ed .acf-input  input[type=checkbox]').not('.clone').each(function () {
  // Check if the non '.clone' row's checkboxes are checked or not. Ignore checkboxes that are in '<tr class="acf-row clone">'
 });



    <table class="acf-table acf-input-table table-layout">
    <thead>
    <tr>
        <th class="acf-th acf-th-rooms" data-key="field_54232c5d030ed">
             Selected Rooms
        </th>
    </tr>
    </thead>
    <tbody>
    <tr class="acf-row">
        <td class="acf-field field_type-checkbox field_key-field_54232c5d030ed" data-name="rooms" data-type="checkbox" data-key="field_54232c5d030ed">
            <div class="acf-input">
                <input type="hidden" name="acf[field_54232c4b030ec][0][field_54232c5d030ed]">
                <ul class="acf-checkbox-list acf-bl">
                    <li><label><input type="checkbox" id="acf-field_54232c4b030ec-0-field_54232c5d030ed" name="acf[field_54232c4b030ec][0][field_54232c5d030ed][]" value="Roof" checked="checked">Roof</label></li>
                    <li><label><input type="checkbox" id="acf-field_54232c4b030ec-0-field_54232c5d030ed-Brackets" name="acf[field_54232c4b030ec][0][field_54232c5d030ed][]" value="Brackets">Brackets</label></li>
                    <li><label><input type="checkbox" id="acf-field_54232c4b030ec-0-field_54232c5d030ed-Fiber Cement Panels" name="acf[field_54232c4b030ec][0][field_54232c5d030ed][]" value="Fiber Cement Panels" checked="checked">Fiber Cement Panels</label></li>
                </ul>
            </div>
        </td>
    </tr>
    <tr class="acf-row clone">
        <td class="acf-field field_type-checkbox field_key-field_54232c5d030ed" data-name="rooms" data-type="checkbox" data-key="field_54232c5d030ed">
            <div class="acf-input">
                <input type="hidden" name="acf[field_54232c4b030ec][acfcloneindex][field_54232c5d030ed]" disabled="disabled">
                <ul class="acf-checkbox-list acf-bl">
                    <li><label><input type="checkbox" id="acf-field_54232c4b030ec-acfcloneindex-field_54232c5d030ed" name="acf[field_54232c4b030ec][acfcloneindex][field_54232c5d030ed][]" value="Roof" disabled="disabled">Roof</label></li>
                    <li><label><input type="checkbox" id="acf-field_54232c4b030ec-acfcloneindex-field_54232c5d030ed-Brackets" name="acf[field_54232c4b030ec][acfcloneindex][field_54232c5d030ed][]" value="Brackets" disabled="disabled">Brackets</label></li>
                    <li><label><input type="checkbox" id="acf-field_54232c4b030ec-acfcloneindex-field_54232c5d030ed-Fiber Cement Panels" name="acf[field_54232c4b030ec][acfcloneindex][field_54232c5d030ed][]" value="Fiber Cement Panels" disabled="disabled">Fiber Cement Panels</label></li>
                </ul>
            </div>
        </td>
    </tr>
    </tbody>
    </table>

Upvotes: 2

Views: 174

Answers (3)

manu144x
manu144x

Reputation: 53

Probably something like this:

$('.acf-row:not(.clone)');

From: http://api.jquery.com/not-selector/

Upvotes: 0

Jon
Jon

Reputation: 126

$("tr.acf-row:not(.clone) input[type=checkbox]").each(function()
{
    // do stuff
});

Upvotes: 1

Ja͢ck
Ja͢ck

Reputation: 173562

You can use the :not() selector to filter out things you don't want.

$('tr.acf-row:not(.clone) :checkbox').each(function() {
});

See also: :checkbox

Upvotes: 2

Related Questions