| | |
display:block to show a table?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2007
Posts: 18
Reputation:
Solved Threads: 0
Hello, and congratulations for this beautiful and meticulous forum.
I have a javascript/html/css issue that I'm trying to solve for about 3 days now, with no luck.
I'm using javascript to toggle the visibility of a certain table. I set the table's display property to none (via js) in order to hide it and to block in order to show it.
However, applying block in the display property of a table seems to be having trouble with firefox.
See below what display:block does to a table in firefox:
This simple html code:
produces this result in firefox:

Notice how the td has the size of the content and does not stretch to the size of the table (although it has a width="100%")? In IE it works fine btw.
If I change my js code to apply "table" to the display property of the table in order to show it, it doesn't show up at all in IE!
Any ideas?
Thanks in advance.
PS: Sorry for any mistakes, my native language is not english
I have a javascript/html/css issue that I'm trying to solve for about 3 days now, with no luck.
I'm using javascript to toggle the visibility of a certain table. I set the table's display property to none (via js) in order to hide it and to block in order to show it.
However, applying block in the display property of a table seems to be having trouble with firefox.
See below what display:block does to a table in firefox:
This simple html code:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<table style="display:block" border="1" width="100%"> <tr><td width="100%">test</td></tr></table>
Notice how the td has the size of the content and does not stretch to the size of the table (although it has a width="100%")? In IE it works fine btw.
If I change my js code to apply "table" to the display property of the table in order to show it, it doesn't show up at all in IE!
Any ideas?
Thanks in advance.
PS: Sorry for any mistakes, my native language is not english
> Hello, and congratulations for this beautiful and meticulous forum.
Hello and welcome. :-)
Now to your problem. 'display' property of CSS decides how an element would be displayed. Since you already have a table, it doesn't make sense to set the display property to table.
Normally this property is used to alter the way a paragraph, a div block or a span block i.e. any container tag displays the data. So what to do when the tag under consideration is a 'table' tag? Simple, set its property to nothing.
and when making it hidden do something like:
Hello and welcome. :-)
Now to your problem. 'display' property of CSS decides how an element would be displayed. Since you already have a table, it doesn't make sense to set the display property to table.
Normally this property is used to alter the way a paragraph, a div block or a span block i.e. any container tag displays the data. So what to do when the tag under consideration is a 'table' tag? Simple, set its property to nothing.
html Syntax (Toggle Plain Text)
<table id="tab" border="1" width="100%"> <tr> <td width="100%">test</td> </tr> </table>
and when making it hidden do something like:
html Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> function hide(id) { document.getElementById(id).style.display = 'none'; } function show(id) { document.getElementById(id).style.display = ''; } </script> </head> <body onmousedown="hide('tab');" onmouseup="show('tab');"> <table id="tab" border="1" width="100%"> <tr> <td>test</td> </tr> </table> </body> </html>
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
Join Date: Jul 2007
Posts: 18
Reputation:
Solved Threads: 0
Thanks for your reply.
Setting the display property to nothing was the first thing I tried, before I even tried block. Mysteriously enough, it didn't work neither in IE nor in any other browser! And that's quite weird because I remember using the exact same techinique in another site I was developing about a year ago...
Setting the display property to nothing was the first thing I tried, before I even tried block. Mysteriously enough, it didn't work neither in IE nor in any other browser! And that's quite weird because I remember using the exact same techinique in another site I was developing about a year ago...
Yes, the visibility property works cross browser. But the catch here is that when the visibility is set to 'hidden', the element is still present there and still contributes to the layout of the page, it just isn't visible.
On the other hand, setting the display property to nothing('') will remove the element and effect the layout of the page since the element is physically not there (though I guess it exists in the DOM since we can always make it come back).
Choose the method which suits you the most in the given scenario keeping the above things in mind. Here is an interesting read.
On the other hand, setting the display property to nothing('') will remove the element and effect the layout of the page since the element is physically not there (though I guess it exists in the DOM since we can always make it come back).
Choose the method which suits you the most in the given scenario keeping the above things in mind. Here is an interesting read.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
Join Date: Nov 2007
Posts: 15
Reputation:
Solved Threads: 1
put your table in a div and apply the display property to the div as below
html Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> function hide(id) { document.getElementById("myTable").style.display = 'none'; } function show(id) { document.getElementById("myTable").style.display = 'block'; } </script> </head> <body onmousedown="hide('tab');" onmouseup="show('tab');"> <div id="myTable" > <table id="tab" border="1" width="100%"> <tr> <td>test</td> </tr> </table> </div> </body> </html>
Last edited by peter_budo; May 29th, 2008 at 7:58 pm. Reason: Keep It Organized - please use [code] tags
![]() |
Similar Threads
- createElement wont show table/div (JavaScript / DHTML / AJAX)
- Mouse Over ToolTip Help (JavaScript / DHTML / AJAX)
- move up n down (C++)
- CSS Div's For Myspace (HTML and CSS)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Preventing trapped key from being added to textarea
- Next Thread: Progress Bar
Views: 8672 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child close codes date debugger decimal dependent developer disablefirebug dom element embed engine enter events ext file firefox flash focus form forms frameworks game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index java javascript javascripthelp2020 javascripts jquery jsp jump libcurl listbox maps marquee masterpage math media menu mp4 onerror onmouseoutdivproblem onmouseover onreadystatechange paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star starrating stretch synchronous toggle tweet unicode variables web webkit webservice window \n






