javascript - Show/hide table row if a child DIV is empty -


i have table multiple entries. after each entry table row edit table row, column spanned cell, inside of div html dynamically loaded into. problem having these empty table rows causes lot of whitespace appear on page when it's rendered.

i understand can't dynamically load html directly cell, have div in load content into.

i want hide table row while child div in empty, , show table row once information has been dynamically loaded child div. dynamically loaded information can removed need hidden again once it's empty again.

<table width="100%">   <tbody>     <tr>       <td>a</td>       <td>b</td>       <td>c</td>     </tr>     <tr style="display: none;">       <td colspan="3"><div></div></td>     </tr>   </tbody> </table>    $("tr").each(function() {     if (this.children().filter(":empty").length) {         this.hide();     } else {         this.show();     } }); 

  • the div isn't child, it's grandchild, children() won't find divs. use context or find instead.

  • you operating hide , show on dom element, not jquery element. need wrap in jquery first.

therefore, run code everytime load something:

//find empty divs , hide it's tr $("div:empty").closest('tr').hide();  //find non-empty divs , show it's tr $("div:not(:empty)").closest('tr').show(); 

and ma! no loops! no each! :d


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -