Home > Net >  Hiding some table rows
Hiding some table rows

Time:09-19

I have a table with some Trs and some Tds have hidden div and other Trs have a displayed divs on click on a button I want to get all the Trs that contain hidden divs only how to do that in jQuery I tried :

$('div[id*="addDiv"]').filter(function() {
                return $(this).css('display') !== 'none';
            }).length;

to get the length of it ang it came correct but i want to get the whole tr data html Code :

 <table >
        <thead>
            <tr>
                <th scope="col">Student Name</th>
                <th scope="col">Student Email</th>
                <th scope="col">Parent Phone</th>
                <th scope="col">Actions</th>
            </tr>
        </thead>
        <tbody>
    <tr id="tr<?php echo $en->id; ?>">
                    <td><?php echo $en->fullname; ?> </td>
                    <td><?php echo $en->email; ?></td>
                    <td id="phone<?php echo $en->id; ?>"><?php echo $parentPhone; ?></td>
                    <td>
                        <div id="addDiv<?php echo $en->id; ?>" <?php if ($parentPhone != "-") {
                                                                    echo "style='display:none;'";
                                                                } ?>><button id='add<?php echo $en->id; ?>' data-toggle='modal' class='fired2 btn btn-primary' data-toggle='addModal' data-target='#addModal' data-id='<?php echo $en->id; ?>'>Add Parent</button>
                      </div>
                        <div id="editDiv<?php echo $en->id; ?>" <?php if ($parentPhone == "-") {                                                                  echo "style='display:none;'";  } ?>>
  <button data-toggle='modal' class='btn btn-success fired' data-toggle='editModal' data-target='#editModal' data-id='<?php echo $en->id; ?>' data-fname='<?php echo $userParent->firstname; ?>' data-lname='<?php echo  $userParent->lastname; ?>' data-phone='<?php echo  $userParent->phone1; ?>' data-email='<?php echo  $userParent->email; ?>' id='edit<?php echo $en->id; ?>'>Edit Parent</button>
                            <button type='button' data-id='<?php echo $en->id; ?>' id='war<?php echo $en->id; ?>' class='btn btn-outline-warning'>Delete Parent</button>
                        </div>
                        <button type="button" data-id="<?php echo $en->id; ?>" id="dang<?php echo $en->id; ?>" >Unenrol student from the course</button>
                    </td>
</tbody>
</table>

CodePudding user response:

Without seeing your actual HTML, this is an assumption, however :has(div:hidden) should work:

let $trWithHiddenDivs = $('#yourTable tr:has(div:hidden)');
  • Related