HighDots Forums  

hiding table rows with javascript and css

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss hiding table rows with javascript and css in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andy Fish
 
Posts: n/a

Default hiding table rows with javascript and css - 01-16-2005 , 11:01 AM






Hi,

I am trying to show/hide a group of table rows using javascript and CSS. if
I group them in a <tbody> element I can do:

my_tbody_element.style.display="none";

to hide them and

my_tbody_element.style.display="block";

to show them. This works in IE but doesn't work in css-compliant browsers,
because these use "table-row-group" instead (which IE doesn't support). I
have tried setting the style to "" or "default" but this doesn't work
either.

is there a simple cross-browser solution to this, or do I have to detect
which browser is in use?

TIA

Andy



Reply With Quote
  #2  
Old   
phil_gg04@treefic.com
 
Posts: n/a

Default Re: hiding table rows with javascript and css - 01-19-2005 , 08:50 PM






I do this sort of thing:

stylesheet:
..hidden {
display: none;
}

script:
my_tbody_element.className="hidden";
my_tbody_element.className="";


I believe this is cross-browser. It is slightly more complicated if
there are other classes present. In this case I have these functions
to add and remove classes:

function add_class(e,c) {
e.className=e.className+" "+c;
}

function remove_class(e,c) {
cn=e.className;
p=cn.indexOf(c);
e.className=cn.substr(0,p)+cn.substr(p+c.length);
}


--Phil.


Reply With Quote
  #3  
Old   
Christoph Paeper
 
Posts: n/a

Default Re: hiding table rows with javascript and css - 01-20-2005 , 02:21 AM



*Andy Fish* <ajfish (AT) blueyonder (DOT) co.uk>:
Quote:
I am trying to show/hide a group of table rows using javascript and CSS.
The correct CSS way would be "visibility: collapse":
<http://www.w3.org/TR/CSS2/tables.html#dynamic-effects>. I've never tried
that and doubt it's well supported, though.

Quote:
my_tbody_element.style.display="none";
my_tbody_element.style.display="block";
IMO the best way of the JS part is a dynamically assigned class, not
'.style'. That's true for almost any JS-CSS interaction, a.k.a. "DHTML".
See <http://webdesign.crissov.de/Scripting/modifyClass.js> for some basic
functions/methods for that.

Quote:
This works in IE but doesn't work in css-compliant browsers, because
these use "table-row-group" instead
tbody.show {display: block; display: table-row-group;}
tbody.hide {display: none;}

Switch¹ between those classes (if the aforementioned method indeed does
not work). It /should/ work and is at least better than JS browser filters.

--
"Music is essentially useless, as life is."
George Santayana


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.