I wanted to hide a table on load and show one of its children td based on class name. Is it possible to do it with CSS?
I tried to do it but I think its inheriting from table which is hidden by display:none;
I wanted to hide a table on load and show one of its children td based on class name. Is it possible to do it with CSS?
I tried to do it but I think its inheriting from table which is hidden by display:none;
If you hide the table, all of the content within the table will be hidden.
You want to hide all the <tr>
s and only show per class
tr{
display:none;
}
tr.showInit{
display:table-row;
}
You can't show a child of a hidden parent.
However you can hide all the other <td>
-s and show just the one you need.
<style>
td { display: none }
td.shown { display: table-cell }
</style>
<table>
<tr>
<td> hidden </td>
<td> hidden </td>
</tr>
<tr>
<td class="shown"> shown </td>
<td> hidden </td>
</tr>
<tr>
<td> hidden </td>
<td> hidden </td>
</tr>
</table>
UPDATE
Using JavaScript
var tds = document.getElementsByTagName("td");
for ( var i = 0, size = tds.length; i < size; i++ ) {
if ( !hasClass( tds[i], "shown" ) ) {
tds[i].style.display = "none";
}
}
function hasClass(element, cls) {
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
hasClass()
function
You cannot show the child and hide a parent .. That is not possible.
Instead hide all the td's you don't want to show ..