473,388 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

hiding table rows with javascript and css

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
Jul 21 '05 #1
2 15033
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.

Jul 21 '05 #2
*Andy Fish* <aj****@blueyonder.co.uk>:

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.
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.
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
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rick Measham | last post by:
I have a set of data that I display in a table. Each row has a category and there may be a dozen or more rows in the same category. I'm looking to add filter buttons to the page to hide/show...
8
by: F. Da Costa | last post by:
Following is a snippet of html in which I hide a whole table and try to hide a single row. Here is my question (plz don't chew my head off if its css related instead): Why does the divTable...
5
by: mt | last post by:
In a nutshell, I'd like to have a list of items, each of which fills out a small table which displays some info about a particular item(the items being a trouble ticket for a tech support ASP-built...
1
by: luvdairish | last post by:
Can someone please look at my code and see why tables are not hiding properly? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Untitled Document</TITLE> <META...
8
by: Andy Fish | last post by:
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 ...
5
by: Ben | last post by:
I have a form for data entry which is in a table. I have a select box to enter a customer name, which takes it's options from the customer database. I have a button to add a new customer. What I...
2
by: c.anandkumar | last post by:
Hi All - I have some problems getting a small piece of javascript working correctly for Firefox. Here is what I am trying to do - 1. I have a form (like a search form) 2. I have many groups...
6
by: Roy | last post by:
Since a datagrid is just an html table anyways, this seems like it should be easy but it's giving me a hard time. In ItemDataBound sub I'm trying to kick off javascript code using response.write()....
1
by: Fix_Metal | last post by:
Hello all. I'm new to this group :) I have a problem with javascript language. I'm making an .asp page with some integrated Javascript functions. The page consists of some HTML selects and a...
2
by: chris f | last post by:
I have an ASP.NET 2 web page that dynamically populates an ASP table in the Page_Load event. Rows relate to different people and I want to let the user display only rows for a particular person...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.