MB34
MB34

Reputation: 4414

$.each() get only items whose parent not hidden

I have an each loop that loops through items in a div.

$(":radio[id^=lt]:checked,:hidden[id^=lt]", "#entry_"+item_id).each(function() {
    // Get values here
});

How would I modify the loop code to get only those whose parent tr is NOT hidden (See CT below)? The input could be a radio OR hidden type.

<div class="entry" style="" id="entry_1117178">
    <table width="100%">
        <tbody>
            <tr>
                <td align="right"><label class="lbl_ln" for="lname_1117178" id="null_1117178">Name on License:&nbsp;</label></td>
                <td align="left"><input type="text" name="lname" class="lname" id="lname_1117178"></td>
            </tr>
            <tr>
                <td align="right"><label class="lbl_lic" for="ln_1117178" id="lbl_1117178">License:&nbsp;</label></td>
                <td align="left"><input type="text" class="ln" name="ln" id="ln_1117178"></td>
            </tr>
            <tr class="InfoCol" id="InfoCol_AL" style="display: none;">
                <td class="TypeCol" id="InfoType_220574">
                    <input type="hidden" class="lt_" id="lt_1117178_220574" name="lt_1117178_220574" value="220574">
                    <label id="lbl_lt_220574" class="lt_" for="lt_1117178"></label>
                </td>
            </tr>
            <tr class="InfoCol" id="InfoCol_CT" style="display: table-row;">
                <td class="TypeCol" id="InfoType_181258">
                    <input type="hidden" class="lt_" id="lt_1117178_181258" name="lt_1117178_181258" value="181258">
                    <label id="lbl_lt_181258" class="lt_" for="lt_1117178"></label>
                </td>
            </tr>
            <tr class="InfoCol" id="InfoCol_DC" style="display: none;">
                <td class="TypeCol" id="InfoType_183820">
                    <input type="radio" class="lt_" id="lt_1117178_183820" name="lt_1117178_183820" value="183820">
                    <label id="lbl_lt_183820" class="lt_" for="lt_1117178_183820">Item 1</label>
                </td>
                <td class="TypeCol" id="InfoType_183821">
                    <input type="radio" class="lt_" id="lt_1117178_183821" name="lt_1117178_183821" value="183821">
                    <label id="lbl_lt_183821" class="lt_" for="lt_1117178_183821">Item 2</label>
                </td>
            </tr>
        </tbody>
    </table>
</div>

In the case of the above code, I just want to get the value of the input whose ID=lt_1117178_181258

Upvotes: 1

Views: 767

Answers (2)

Abe Miessler
Abe Miessler

Reputation: 85056

This seems a bit cleaner:

$("input", ".InfoCol:visible").each(function() {
  //whatever
});

It might be a little over simplified, but based on the html you have shown I think it might work...

Upvotes: 1

adeneo
adeneo

Reputation: 318232

$(":radio[id^=lt]:checked,:hidden[id^=lt]", "#ce_entry_"+item_id).each(function() {
    if ( $(this).closest('tr').is(':visible') ) {
        // Get values here
    }
});

Upvotes: 3

Related Questions