cross browser - CSS display:inline/none with tables works with Firefox but not Chrome or Safari -


i working on quick , dirty application involves several single-column tables displayed horizontally within outer table.

|-------------------------------------------| |             outer table                   | |-------------------------------------------| |    ---------    ---------    ---------    | |    | table 1|   |table 2|    |table 3|    | |    ---------    ---------    ---------    | |    | row 1  |   | row 1 |    | row 1 |    | |    ---------    ---------    ---------    | |    ...                                    | |    ---------    ---------    ---------    | |    | row n  |   | row n |    | row n |    | |    ---------    ---------    ---------    | |                                           | |-------------------------------------------|          ---------    ---------             |show #2|    |show #3|         ---------    ---------     

i realize done using css without tables, not adept enough , doesn't need elegant. @ start, first table displayed. clicking buttons toggles display "none" "inline" (i tried "block") of #2 , #3. in example, set style of #2 in div around table , in #3 within td around table. both methods work in firefox 22.0 not in chrome 27.0 or safari 5.0 (all on mac). there solution using tables? or, if you'd design style sheet, works :-)

<html> <body>  <table id = "main" border=0 cellspacing=20>      <tr>         <td>             <table id = "tbl1" border=0>                  <tr><td> table #1, row #1 </td></tr>                 <tr><td> table #1, row #2 </td></tr>             </table>         </td>          <td>             <!-- hide table hidden div -->              <div id = "tbl2" style="display:none">               <table border=0>                 <tr><td> table #2, row #1 </td></tr>                 <tr><td> table #2, row #2 </td></tr>             </table>            </div>        </td>         <!-- hide table hidden td -->         <td id = "tbl3" style="display:none">           <table border=0>             <tr><td> table #3, row #1 </td></tr>             <tr><td> table #3, row #2 </td></tr>         </table>       </td>    </tr> </table>   <br>  <input type=button value ='show table #2' onclick='document.getelementbyid("tbl2").style="display:inline"'> <input type=button value ='show table #3' onclick='document.getelementbyid("tbl3").style="display:inline"'> <br> <br> <input type=button value ='hide table #2' onclick='document.getelementbyid("tbl2").style="display:none"'> <input type=button value ='hide table #3' onclick='document.getelementbyid("tbl3").style="display:none"'>  </body> </html> 

here's a working example. while making it, didn't know did not want use jquery, recommend change mind, since have adding html, preferably before closing </body> tag:

<script src="http://code.jquery.com/jquery-1.7.2.min.js"> $(document).ready(function () {   $('input').on("click", function () {       var inputvalue = $(this).val();       var index = inputvalue.indexof("#")       var divid = "#tbl" + inputvalue.substr(index+1);       $(divid).toggle();   });  }); </script> 

i changed html bit: i'm using 1 input per table: "show or hide" in 1 button. can ofcourse use 2 buttons it: change jquery , call hide() or show() accordingly. if don't wanna use jquery, convert example pure javascript, seems that's gonna take bit more coding :)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -