473,394 Members | 1,693 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,394 software developers and data experts.

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.getElementById(id)){
document.getElementById(id).style.position = 'relative';
document.getElementById(id).style.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 11908
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.getElementsByTagName(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');return false">Hide divs</a>

.....

HTH;
JW

Jul 20 '05 #2
On Wed, 21 Jan 2004 23:39:17 +0100, Janwillem Borleffs <jw@jwscripts.com>
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.******@blueyonder.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.com> 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.getElementsByTagName(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_by_name(me,id, pluspic){

var tags = document.getElementsByName(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');return 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.com> 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_by_name(me,id, pluspic){

var tags = document.getElementsByName(id);


AFAIK, document.getElementsByTagName only applies to form elements.
JW

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

var tags = document.getElementsByName(id);


AFAIK, document.getElementsByTagName only applies to form elements.


No, any DOM Node has getElementsByTagName as a method. If you meant
getElementsByName, DOM 2 says:

getElementsByName
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/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #10
Janwillem Borleffs wrote:
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_by_name(me,id, pluspic){

var tags = document.getElementsByName(id);

AFAIK, document.getElementsByTagName only applies to form elements.


<div>test</div>
<script type="text/javascript">
alert(document.getElementsByTagName('div'))
</script>

IE6: alerts [object]
Opera 7: alerts [object nodeList]
NS7: alerts [object HTMLCollection]

<script type="text/javascript">
alert(document.getElementsByName('myDiv'))
</script>

Gives similar results.

I hunted a reference on MSDN but obviously didn't know where to hunt it :(

--
Randy
Chance Favors The Prepared Mind

Jul 20 '05 #11
On Thu, 22 Jan 2004 00:46:28 +0100, Janwillem Borleffs <jw@jwscripts.com>
wrote:
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_by_name(me,id, pluspic){

var tags = document.getElementsByName(id);


AFAIK, document.getElementsByTagName only applies to form elements.


Using

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
...

and calling

alert( document.getElementsByTagName('meta').length );

returns '3'.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #12
Hi!

On Wed, 21 Jan 2004 19:17:37 -0500, Randy Webb
<hi************@aol.com> wrote:
Janwillem Borleffs wrote:
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_by_name(me,id, pluspic){

var tags = document.getElementsByName(id);

AFAIK, document.getElementsByTagName only applies to form elements.


<div>test</div>
<script type="text/javascript">
alert(document.getElementsByTagName('div'))
</script>

IE6: alerts [object]
Opera 7: alerts [object nodeList]
NS7: alerts [object HTMLCollection]

<script type="text/javascript">
alert(document.getElementsByName('myDiv'))
</script>

Gives similar results.

I hunted a reference on MSDN but obviously didn't know where to hunt it :(


http://msdn.microsoft.com/workshop/a...entsbyname.asp

Like always, its not fully described. It returns a collection, but an
empty one.

This works
var tags = document.body.getElementsByTagName('tr');

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

and doesn't work with getElementsByName


HTH, Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 20 '05 #13

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

Similar topics

12
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
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 {...
4
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...
2
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
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...
5
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...
2
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...
15
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...
2
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 ...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.