function sizeTbl(h, id) {
var tbl = document.getElementById(id);
tbl.style.display = h;
}
.checkStyleSheet{
font-size: 20px;
font-weight: strong;
background-color: black;
color: white;
/*You can make your style by section if you find jQuery too hard, or just not
pertinent to learn at the moment and you are forced to use PureJS and id each
element on an individual basis.*/
}
.firstGroup table{
color: red;
}
<head>
<title>Pure JS - No jQuery</title>
</head>
<body>
<div>
for tbl
<a href="javascript:sizeTbl('none', 'tbl')">Hide</a>
<a href="javascript:sizeTbl('block', 'tbl')">Expand</a>
<p>
Some text before
</p>
<div id="tbl" name="tbl" style="overflow:hidden;display:none">
<table border="1">
<tr><td>test</td></tr>
<tr><td>test</td></tr>
<tr><td>test</td></tr>
</table>
</div>
<p>
some text after
</p>
</div>
<div>
for tbl2
<a href="javascript:sizeTbl('none', 'tbl2')">Hide</a>
<a href="javascript:sizeTbl('block', 'tbl2')">Expand</a>
<p>
Some text before
</p>
<p> Still fine with nesting </p>
<div>
<div id="tbl2" name="tbl2" style="overflow:hidden;display:none">
<table border="1">
<tr><td>test</td></tr>
<tr><td>test</td></tr>
<tr><td>test</td></tr>
</table>
</div>
<p>
some text after
</p>
</div>
</div>
<!-- Here, we style a group with red -->
<section class="firstGroup">
<div>
for tbl3 - RED
<a href="javascript:sizeTbl('none', 'tbl3')">Hide</a>
<a href="javascript:sizeTbl('block', 'tbl3')">Expand</a>
<p>
Some text before
</p>
<div id="tbl3" name="tbl3" style="overflow:hidden;display:none">
<table border="1">
<tr><td>test</td></tr>
<tr><td>test</td></tr>
<tr><td>test</td></tr>
</table>
</div>
<p>
some text after
</p>
</div>
<div>
for tbl4 - RED
<a href="javascript:sizeTbl('none', 'tbl4')">Hide</a>
<a href="javascript:sizeTbl('block', 'tbl4')">Expand</a>
<p>
Some text before
</p>
<div id="tbl4" name="tbl4" style="overflow:hidden;display:none">
<table border="1">
<tr><td>test</td></tr>
<tr><td>test</td></tr>
<tr><td>test</td></tr>
</table>
</div>
<p>
some text after
</p>
</div>
<div>
for tbl5 - RED
<a href="javascript:sizeTbl('none', 'tbl5')">Hide</a>
<a href="javascript:sizeTbl('block', 'tbl5')">Expand</a>
<p>
Some text before
</p>
<div id="tbl5" name="tbl5" style="overflow:hidden;display:none">
<table border="1">
<tr><td>test</td></tr>
<tr><td>test</td></tr>
<tr><td>test</td></tr>
</table>
</div>
</section>
<p>
some text after
</p>
</div>
<div>
for tbl6
<a href="javascript:sizeTbl('none', 'tbl6')">Hide</a>
<a href="javascript:sizeTbl('block', 'tbl6')">Expand</a>
<p>
Some text before
</p>
<div id="tbl6" name="tbl6" style="overflow:hidden;display:none">
<table border="1">
<tr><td>test</td></tr>
<tr><td>test</td></tr>
<tr><td>test</td></tr>
</table>
</div>
<p>
some text after
</p>
</div>
<!-- Note, that this solution is fine, and you can place your anchor tags anywhere.
the same capabilty exists to find the table regardless of nesting however, you
must ID every individual table, and therefore provide individual CSS for each.
if you were to change your tables and your JS calls from your anchors to class
based styling, then you would "show" or "hide" ALL tables from any anchor click
of expand/hide. You could probably solve that with classing your actual tables
elements, and handle individual styling by id if necessary. You could also create
a "section" tag in html to class groups of tables (or as you're calling them columns?)
If you do truly mean "columns" and you want to know how to have 1 table, with mult.
columns you can selectively Hide/Show that's slightly different. See below:
-->
<section class="checkStyleSheet">
<!-- Notice the "section tag, which you can use to style groups of tables with individual id's if necessary -->
<div>
for tbl7
<a href="javascript:sizeTbl('none', 'tbl7')">Hide</a>
<a href="javascript:sizeTbl('block', 'tbl7')">Expand</a>
<p>
Some text before
</p>
<div id="tbl7" name="tbl7" columns="3" style="overflow:hidden;display:none">
<table border="1">
<tr>
<td><a href="javascript: alert('JS to hide col');">H :</a><a href="javascript: alert('JS to show col');"> S</a></td>
<td><a href="javascript: alert('JS to hide col');">H :</a><a href="javascript: alert('JS to show col');"> S</a></td>
<td><a href="javascript: alert('JS to hide col');">H :</a><a href="javascript: alert('JS to show col');"> S</a></td>
</tr>
<tr><td>test</td><td>test</td><td>test</td></tr>
<tr><td>test</td><td>test</td><td>test</td></tr>
<tr><td>test</td><td>test</td><td>test</td></tr>
</table>
</div>
<p>
some text after
</p>
</div>
</section>
將ID作爲參數傳遞給函數 –