views:

35

answers:

2

Hi, I want to hide/unhide a group of HTML Table rows using javascript. To do so, I define each such row, whose visibility is to be toggled, as follows: When an appropriate event is fired, I toggle its state as follows:

document.getElementById('rowId1').style.display = 'none';//or 'block'

The above code works in both firefox and IE. But while IE retains proper shape of the table, firefox loses all sense of decorum and the HTML table displayed is totally haphazard.

Am I missing out anything important? I have ensured that the CSSClass of the individual elements are defined in the CSS file.

Regards, Vipul

+2  A: 

Don't use display: block for table elements on firefox.

Use display: table-row for rows instead.

Sadly, IE (up to 8) does not support this standard.

More on the issue here: http://www.w3schools.com/css/pr_class_display.asp

vassilis
+1. To remain compatible with IE, you could wrap `display = 'table-row';` in a try block and resort to `display = 'block';` in the catch block.
casablanca
Thanks a lot for the answer. For the time being though, the simple trick of substituting 'block' with "" worked. I haven't tried my application on any other browser. If it fails anywhere, I would have to consider this aspect. Thanks again.
Vipul
A: 

Try toggling between "none" and "".

Álvaro G. Vicario
Thanks. It works!
Vipul