1

I've looked at a couple of similar questions here but I still can's seem to get it to work. I'm trying to hide specific columns in a table that is being automatically generated on the page. I've managed to hide column header and the corresponding cells in the first row but I'm not sure how to make it work for the rest of the rows. What am I missing?

$(document).ready(function() {
    $("table.lc_Table:eq(0) tr:eq(0) th").each(function(ind,ele) {
        if( $.trim($(this).text()).match(/(Available|Order Limit)/gi) )
        {
          $("table.lc_Table:eq(0) tr th:eq("+ind+"), table.lc_Table:eq(0) tr td:eq("+ind+")").hide();
        }
    });
});

<table border="0" cellspacing="0" cellpadding="4" class="lc_Table">
<tr>
    <th class="lc_Heading">
        <p class="PaddedListHeadingsC">Ticket Class</p>
    </th>
    <th class="lc_Heading">
        <p class="PaddedListHeadingsC">Available</p>
    </th>
    <th class="lc_Heading">
        <p class="PaddedListHeadingsC">Order Limit</p>
    </th>
    <th class="lc_Heading">
        <p class="PaddedListHeadingsC">Price</p>
    </th>
</tr>
<tr class="lc_Row0">
    <td class="lc_Cell">
        <p>Attendee1</p>
    </td>
    <td align="right" class="lc_Cell">
        <p>50</p>
    </td>
    <td align="right" class="lc_Cell">
        <p>No Limit</p>
    </td>
    <td align="right" class="lc_Cell">
        <p>$0.00</p>
    </td>
</tr>
<tr class="lc_Row1">
    <td class="lc_Cell">
        <p>Attendee2</p>
    </td>
    <td align="right" class="lc_Cell">
        <p>50</p>
    </td>
    <td align="right" class="lc_Cell">
        <p>No Limit</p>
    </td>
    <td align="right" class="lc_Cell">
        <p>$0.00</p>
    </td>
</tr>

1

2 Answers 2

3

Should work

$('tr').each(function(){
    $(this).find('td').eq(0).hide();
})

For both TH & TD can use

$('tr').each(function(){
    $('tr').children().eq(0).hide();
})
Sign up to request clarification or add additional context in comments.

Comments

0

:eq is evaluating to only one element. Instead use :nth-child which counts relative to an elements parent.

1 Comment

This worked like a charm thanks... this is what I ended up with. $(document).ready(function() { $("table.lc_Table:eq(0) tr:eq(0) th").each(function(ind,ele) { if( $.trim($(this).text()).match(/(Available|Order Limit)/gi) ) { $("table.lc_Table:eq(0) tr th:nth-child("+(ind+1)+"), table.lc_Table:eq(0) tr td:nth-child("+(ind+1)+")").hide(); } }); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.