Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding table data using <div style="display:none">

Tags:

html

css

So, I've hidden whole tables like this, which works fine:

<div style="display:none"> <table> <tr><th>Test Table</th><tr> <tr><td>123456789</td><tr> <tr><td>123456789</td><tr> <tr><td>123456789</td><tr> </table> </div> 

But I want to hide just a group of rows like this:

<table> <tr><th>Test Table</th><tr> <div style="display:none"> <tr><td>123456789</td><tr> <tr><td>123456789</td><tr> <tr><td>123456789</td><tr> </div> </table> 

But that doesn't work. Any hints?

like image 732
joedborg Avatar asked Aug 02 '11 10:08

joedborg


People also ask

How do I hide data in a table?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <table> element is not visible, but it maintains its position on the page. Removing the hidden attribute makes it re-appear.

How do you hide a table in CSS?

Usually, to hide an element from view, you use the 'display' property and set it to 'none'. But CSS also has a property called 'visibility', which hides elements in a different way. In particular, we use 'visibility: collapse' here, which is designed especially for hiding table columns and rows.

How do you style display none?

Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”. document. getElementById("element").


2 Answers

Just apply the style attribute to the tr tag. In the case of multiple tr tags, you will have to apply the style to each element, or wrap them in a tbody tag:

<table>   <tr><th>Test Table</th><tr>   <tbody style="display:none">     <tr><td>123456789</td><tr>     <tr><td>123456789</td><tr>     <tr><td>123456789</td><tr>   </tbody> </table> 
like image 95
Ben Rowe Avatar answered Oct 12 '22 01:10

Ben Rowe


Unfortuantely, as div elements can't be direct descendants of table elements, the way I know to do this is to apply the CSS rules you want to each tr element that you want to apply it to.

<table> <tr><th>Test Table</th><tr> <tr><td>123456789</td><tr> <tr style="display: none; other-property: value;"><td>123456789</td><tr> <tr style="display: none; other-property: value;"><td>123456789</td><tr> <tr><td>123456789</td><tr> <tr><td>123456789</td><tr> </table> 

If you have more than one CSS rule to apply to the rows in question, give the applicable rows a class instead and offload the rules to external CSS.

<table> <tr><th>Test Table</th><tr> <tr><td>123456789</td><tr> <tr class="something"><td>123456789</td><tr> <tr class="something"><td>123456789</td><tr> <tr><td>123456789</td><tr> <tr><td>123456789</td><tr> </table> 
like image 37
Delan Azabani Avatar answered Oct 12 '22 01:10

Delan Azabani