473,671 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide multiple elements by name

Hi!

I have a dynamically generated page (PHP), which contains an Explorer
like view of items. I would like to hide multiple <tr>'s by name, but
I can't figure out how thats done.

I have this code to hide one element by id

if (document.getEl ementById(id)){
document.getEle mentById(id).st yle.position = 'relative';
document.getEle mentById(id).st yle.display = 'none';
}

Anyone has a cod sample for looping through multiple elements and hide
them?

Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 20 '05 #1
12 11928
Jochen Daum wrote:
Hi!

I have a dynamically generated page (PHP), which contains an Explorer
like view of items. I would like to hide multiple <tr>'s by name, but
I can't figure out how thats done.
.... Anyone has a cod sample for looping through multiple elements and hide
them?


<script type="text/javascript">
function hide(t, id) {
var tags = document.getEle mentsByTagName( t);
for (var i = 0; i < tags.length; i++) {
if (tags[i].id == id) {
tags[i].style.display = 'none';
}
}
}
</script>

.....
<div id="sid">A</div>
<div id="impid">B</div>
<div id="sid">C</div>
<div id="impid">D</div>

.....
<a href="#" onclick="hide(' div','sid');ret urn false">Hide divs</a>

.....

HTH;
JW

Jul 20 '05 #2
On Wed, 21 Jan 2004 23:39:17 +0100, Janwillem Borleffs <jw@jwscripts.c om>
wrote:

<snip>
<div id="sid">A</div>
<div id="impid">B</div>
<div id="sid">C</div>
<div id="impid">D</div>


<snip>

Which is, of course, invalid HTML.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
Michael Winter wrote:
Which is, of course, invalid HTML.


What is invalid about that?

JW

Jul 20 '05 #4
Hi Janwillem!

On Wed, 21 Jan 2004 23:39:17 +0100, "Janwillem Borleffs"
<jw@jwscripts.c om> wrote:
Jochen Daum wrote:
Hi!

I have a dynamically generated page (PHP), which contains an Explorer
like view of items. I would like to hide multiple <tr>'s by name, but
I can't figure out how thats done.
...
Anyone has a cod sample for looping through multiple elements and hide
them?


<script type="text/javascript">
function hide(t, id) {
var tags = document.getEle mentsByTagName( t);
for (var i = 0; i < tags.length; i++) {
if (tags[i].id == id) {
tags[i].style.display = 'none';
}
}
}
</script>

Wouldn't that also be working with any tag, if I did it like this. It
doesn't give me an error, but it doesn't work either:

function hide_elements_b y_name(me,id, pluspic){

var tags = document.getEle mentsByName(id) ;
for (var i = 0; i < tags.length; i++) {
if (tags[i].name == id) {
tags[i].style.display = 'none';
}
}
}

and the tags being:

<tr name="xyz">

??

Jochen

....
<div id="sid">A</div>
<div id="impid">B</div>
<div id="sid">C</div>
<div id="impid">D</div>

....
<a href="#" onclick="hide(' div','sid');ret urn false">Hide divs</a>

....

HTH;
JW


--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 20 '05 #5
Michael Winter wrote:
Which is, of course, invalid HTML.


Never mind, see what you mean.

JW

Jul 20 '05 #6
Hi!

On Thu, 22 Jan 2004 00:27:04 +0100, "Janwillem Borleffs"
<jw@jwscripts.c om> wrote:
Michael Winter wrote:
Which is, of course, invalid HTML.


Never mind, see what you mean.

Does he mean the double use of an id?

Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 20 '05 #7
Jochen Daum wrote:
Does he mean the double use of an id?


Yep
Jul 20 '05 #8
Jochen Daum wrote:
Wouldn't that also be working with any tag, if I did it like this. It
doesn't give me an error, but it doesn't work either:

function hide_elements_b y_name(me,id, pluspic){

var tags = document.getEle mentsByName(id) ;


AFAIK, document.getEle mentsByTagName only applies to form elements.
JW

Jul 20 '05 #9
"Janwillem Borleffs" <jw@jwscripts.c om> writes:

var tags = document.getEle mentsByName(id) ;


AFAIK, document.getEle mentsByTagName only applies to form elements.


No, any DOM Node has getElementsByTa gName as a method. If you meant
getElementsByNa me, DOM 2 says:

getElementsByNa me
With [HTML 4.01] documents, this method returns the (possibly empty)
collection of elements whose name value is given by elementName. In
[XHTML 1.0] documents, this methods only return the (possibly empty)
collection of form controls with matching name. This method is case
sensitive.

So yes and no, in XHTML it's only form controls. In HTML, it's
anything with a name attribute.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #10

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

Similar topics

12
8870
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
2
12182
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow { display: none; }
4
8724
by: itunes66 | last post by:
how can i do this i already have a function to show/hide elements with one link but how can i show/hide multiple elements here is the script function obj_ref(object) { if (document.getElementById) { return document.getElementById(object);
2
13311
by: Eero Tuomenoksa | last post by:
Hi Does someone knows how i can show/hide multible divs at one click? -- Käytössä Operan vallankumouksellinen sähköpostiohjelma: http://www.opera.com/mail/
1
16742
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
5
8425
by: ali | last post by:
Hello every one i need you help regarding div hide and show. i am having a link like <a href="#" onClick="expandWin()">show/hide </a> <div id=showHide> </div> within div i have lots of form tags and div elements say n. The problem
2
2269
by: dinkle | last post by:
Hi Y'all, I am pretty new to js and am hitting a few snags. I need to process a multiple select list and pass it onto a PHP script. I can only get the first value in the JS and have no idea how to grab the rest and successfully pass the array onto my php script. No books, foums, examples, tutorials or anything I have spent most of my recent waking hours reading and downtime dreaming about appear to cover this and I am starting to think...
15
3801
by: worked | last post by:
I have a script that hides / shows form elements, and wrapped in a tab script (tab navigation). When the code is duplicated (per tab content), the hide / show function works for the first tab but breaks in each subsequent tab. Why? Help appreciated! Example: http://geocities.com/edmurphy21/ hide / show script: <script type="text/javascript"> function showHide() { var idx = this.id.split('-'); var sp =...
2
2773
by: helplakshmi | last post by:
Hi All, I am new to php. The form that i am designing has few input input fields with submit and reset button. The functionality of submit and reset are working properly till now. My form <form name="search" id="search" action= "search.php" method = "post" onreset="formReset(this);return false;"> <table cellspacing="1" cellpadding="1" > <tr> <!-- Input field for responsible-->
0
8392
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
8912
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
8819
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
8597
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
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
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...
2
1807
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.