473,624 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to hide table rows with the help of getElementsByNa me()?

AR
Hi,
How can I hide table rows? ... tried with the following example:
FireFox works... How to do the simillar in IE6?

<html>
<head>
<script language="javas cript">
function hide_row() {
var v = document.getEle mentsByName("tr Book");
v[0].style.display = 'none';
v[1].style.display = 'none';
v[2].style.display = 'none';
}
</script>
</head>
<body>
<table>
<tr name="trBook">< td>line1</td></tr>
<tr name="trBook">< td>line2</td></tr>
<tr name="trBook">< td>line3</td></tr>
</table>
<input type=button name="v" value="Hide" onclick="hide_r ow()">
</body>
</html>

Thanks in advance

AR

Jul 23 '05 #1
3 16930


AR wrote:

var v = document.getEle mentsByName("tr Book"); <tr name="trBook">< td>line1</td></tr>
<tr name="trBook">< td>line2</td></tr>
<tr name="trBook">< td>line3</td></tr>


The name attribute is not defined for <tr> elements so you are relying
on browser quirks to give you a result with getElementsByNa me. Consider
accessing the table and then its rows collection if you want to script
the <tr> elements in that table.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
AR wrote:
Hi,
How can I hide table rows? ... tried with the following example:
FireFox works... How to do the simillar in IE6?

<html>
<head>
<script language="javas cript">
function hide_row() {
var v = document.getEle mentsByName("tr Book");
v[0].style.display = 'none';
v[1].style.display = 'none';
v[2].style.display = 'none';
}
</script>
</head>
<body>
<table>
<tr name="trBook">< td>line1</td></tr>
<tr name="trBook">< td>line2</td></tr>
<tr name="trBook">< td>line3</td></tr>
</table>
<input type=button name="v" value="Hide" onclick="hide_r ow()">
</body>
</html>

Thanks in advance

AR


document.getEle mentsByName() is only implemented for input and img
elements in iewin/Opera. Use a TBODY with an id:

function hide_row()
{
var el;
if (document.getEl ementById
&& (el = document.getEle mentById('trBoo k')))
{
el.style.displa y = 'none';
}
}
..........
<table>
<tbody id="trBook">
<tr><td>line1 </td></*tr>
<tr><td>line2 </td></*tr>
<tr><td>line3 </td></*tr>
</tbody>
</table>

If you need to do this with individual rows, you can use a naming
convention of some sort, or selectively apply the
..getElementsBy TagName() method.

Jul 23 '05 #3
On Thu, 30 Jun 2005 09:24:22 -0700, AR <ar********@yah oo.com> wrote:
Yes, as Martin said, use the rows[] collection for the table element:

document.getEle mentById('YOURT ABLEIDHERE').ro ws[3].style.display= 'none';
//sets the
style.display for it to 'none';

Another way will be using associative IDs for the relevant elements and
iterate
through them.

Danny

--Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #4

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

Similar topics

3
27137
by: Harry | last post by:
I want to provide a drill down facility for the users - the plan is to intially display a table with summary rows containing results of previous selected search criteria. In each summary row you have a button to drill down i.e which displays X number of rows with results that make up the summary row value. When "drilled down" also provide a button to "collapse" the detail rows! Is it possible to show/hide individual rows in a table? -...
2
4946
by: KathyB | last post by:
Hi, I'm trying to get the following script to work, but I'm getting an error saying "rowID is undefined". function showhide(rowId) { var showRow = "Edit_" + rowID var hideRow = "View_" + rowID document.getElementById(showRow).style.display ="block"; document.getElementById(hideRow).style.display = "none"; }
2
8220
by: Mark | last post by:
Hi, I need to be able to have five different links and when when someone clicks to show row 2, row 1 automatically hides. Right now all i can figure out is a link that will show but then you have to click the same link to hide. I want to be able to turn off a row when another row is clicked on to show? Can someone help?
5
2326
by: Marek Mänd | last post by:
Please explain to a experienced fool like me, how to hide table rows correctly at this case. http://marekmand.kuubik.ee/iebug_canthide_table_rows_properly.htm Click on the header "label" and see how IE6 SP1 draws the borders wrongly. How it can be patched? Does that mean, that with the collapsed border table model one cannot set the display of rows successfully with no side effects in IE6 SP1?
9
33431
by: Wang, Jay | last post by:
I try to group several rows in a table into a div and show/hide them by click on a button somewhere with a javascript link. When clicked, the link will toggle the style of the div section's style between BLOCK and NONE. This technique works on normal text fine, but it doesn't work on part of the table, is there a solution that I can achieve the goal of turning on/off several rows all together? Thanks.
1
2115
by: RA | last post by:
Hi I want to have a FAQ so that when the user clicks the question the answer will be shown below the questions. How do I do it? I use c# with asp.net. Thanks
1
1893
by: shankwheat | last post by:
I'm creating a dynamic table with asp and I would like to add a "Show All" and "Collapse All" feature to show/hide certain rows within the table. This code works well for showing/hiding one row at a time but I'm not sure how to all the "Show All/Hide All" feature. Thanks. function sh_RowShowHide(sh_RowID) { var currRow = document.getElementById(sh_RowID); if (currRow.style.display=="none") { currRow.style.display="";...
11
8014
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to display. If they put a value in the text box in the second row then display the third row etc. etc. etc. to 10 rows. I'm pretty new to javascript, so I'm not to sure where to start. Any help would be great, thanks a lot.
1
7403
by: jbreaker | last post by:
Hi - I have a table with about 30 rows, which contain a checkbox and a bit of text each. What I'm trying to find a way to do is to have 2 buttons at the bottom of the page - HIDE & SHOW. When the HIDE button is clicked, I need to hide all the table rows which contain UNCHECKED textboxes. When the SHOW button is clicked, I want to restore the visibility of all the rows. I need to do this in JavaScript (which is what I'm having trouble with)...
0
8242
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.