html - Uneven table cells when changing display none -


i having trouble html tables when hide , show rows using javascript (display:block). need hide rows through javascript when re-show rows, find table grid layout lost , hidden row collapsed left side of grid.

my sandbox code follows:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css">     table {     }     .rowa {         background-color: #70cdb3;     }     .rowb {         background-color: #fff1dc;     }     .rowc {         background-color: #edc7ff;     }     .cell {         border: solid 3pt white;         width:25%;     }     {         cursor: pointer;     } </style>  <script type='text/javascript'>     function hide(elemid) {         var elem=document.getelementbyid(elemid);         elem.style.display='none';     }      function show(elemid) {         var elem=document.getelementbyid(elemid);         elem.style.display='block';     } </script> </head> <body>  <table> <tr class='rowa'>     <td class='cell'>     <a onclick="hide('row1')">hide row1</a>     </td>     <td class='cell'>     <a onclick="show('row1')">show row1</a>     </td> </tr> <tr class='rowb'>     <td class='cell'>     <a onclick="hide('row2')">hide row2</a>     </td>     <td class='cell'>     <a onclick="show('row2')">show row2</a>     </td> </tr> <tr class='rowc'>     <td class='cell'>     <a onclick="hide('row3')">hide row3</a>     </td>     <td class='cell'>     <a onclick="show('row3')">show row3</a>     </td> </tr> </table> <hr> <table class='table' style='width:50%'> <thead> <tr>     <th>id</th>     <th>name</th>     <th>job</th>     <th>email</th> </tr> </thead> <tbody> <tr class='rowa' id='row1'>     <td class='cell'>one</td>     <td class='cell'>johnny five</td>     <td class='cell'>robotin'</td>     <td class='cell'>need@input.com</td> </tr> <tr class='rowb' id='row2'>     <td class='cell'>two</td>     <td class='cell'>super notsolong</td>     <td class='cell'>doin' stuff</td>     <td class='cell'>doing@stuff.com</td> </tr> <tr class='rowc' id='row3'>     <td class='cell'>three</td>     <td class='cell'>super superlonglastnamesmith</td>     <td class='cell'>doin' stuff</td>     <td class='cell'>doing@stuff.com</td> </tr> </tbody> </table>   </body> </html> 

using sandbox, problem when click on hide row buttons @ top of sandbox, , show row again - rows cells collapse left.

note, seems occur in ie 10, edge, chrome, , firefox, not ie9

what doing wrong?

thanks

a

the default display option table rows table-row, can't use block.

function show(elemid) {     var elem=document.getelementbyid(elemid);     elem.style.display='table-row'; } 

when in doubt can set blank value display property, return default value.

this work too.

function show(elemid) {     var elem=document.getelementbyid(elemid);     elem.style.display=''; } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -