473,473 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Wildcard for getElementById

Is there any wildcard, like *, for addressing all the element ID's on the
page at once, like if you want to hide all layers at once. For example:

document.getElementById('*').style.visibility = 'hidden';

I know the above doesn't work but you get what I'm driving at right? Is
there anything like that for that method or in javascript in general?
Thanks.
Jul 20 '05 #1
5 38834
<script language="javascript">
/* browser compatibility NOT tested!
For this script, you have your 'parent' activator, and you have your target div
layer.
when you call the function in the html page
ie: onClick="changeDiv('child_layer_id')"
you pass the child layer's id which you
want to only show while all the other
divs are hidden; of course, just comment out the display:block code and all
the divs on the page (with the special attribute code) remain hidden
*/

function changeDiv(divid){

// create object of all div tags in the document
var tag = document.getElementsByTagName('DIV')

// create the child layer object using the argument passed to the function
var elid = document.getElementById(divid);

//the show/hide layer has an attribute nav="yes" in it
// to distiguish it from other DIV elements in the page
// by determining if that DIV element has the attribute
// i can make sure i'm affecting the show/hide layer DIV

if(elid.getAttribute("nav")){
for(x=0; x<tag.length; x++){
//hide all div layers with the 'nav' attribute
if(tag[x].getAttribute("nav")){
tag[x].style.display="none";
}
// show only the layer with the id passed as the argument
// by the main function
elid.style.display="block";
}
}
}
</script>
Hope this helps!

~Jim
Jul 20 '05 #2
"TheKeith" <no@spam.com> writes:
Is there any wildcard, like *, for addressing all the element ID's on the
page at once, like if you want to hide all layers at once. For example:

document.getElementById('*').style.visibility = 'hidden';
No. You only get one element with getElementById, so using a wildcard
doesn't make sense. Even if it returned more than one element, you can't
use .style.visiblity on the collection and hope it affects the contents.
I know the above doesn't work but you get what I'm driving at right? Is
there anything like that for that method or in javascript in general?


What you can use instead is:

var elems = document.getElementsByTagName("*"); // yes, wildcards do exist
for (var i=0;i<elems.length;i++) {
if ( .... elems[i] .... ) { // you probably don't want to hide *all* elements
elems[i].style.visibility="hidden";
}
}
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Demo: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

"JimMenees" <ji*******@aol.comNoSpam> wrote in message
news:20***************************@mb-m23.aol.com...
<script language="javascript">
/* browser compatibility NOT tested!
For this script, you have your 'parent' activator, and you have your target div layer.
when you call the function in the html page
ie: onClick="changeDiv('child_layer_id')"
you pass the child layer's id which you
want to only show while all the other
divs are hidden; of course, just comment out the display:block code and all the divs on the page (with the special attribute code) remain hidden
*/

function changeDiv(divid){

// create object of all div tags in the document
var tag = document.getElementsByTagName('DIV')

// create the child layer object using the argument passed to the function
var elid = document.getElementById(divid);

//the show/hide layer has an attribute nav="yes" in it
// to distiguish it from other DIV elements in the page
// by determining if that DIV element has the attribute
// i can make sure i'm affecting the show/hide layer DIV

if(elid.getAttribute("nav")){
for(x=0; x<tag.length; x++){
//hide all div layers with the 'nav' attribute
if(tag[x].getAttribute("nav")){
tag[x].style.display="none";
}
// show only the layer with the id passed as the argument
// by the main function
elid.style.display="block";
}
}
}
</script>
Hope this helps!

Thanks a lot. I was really just hoping there was a wild card in general, but
thanks anyway. The visbility was just an example.
Jul 20 '05 #4

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:oe**********@hotpop.com...
"TheKeith" <no@spam.com> writes:
Is there any wildcard, like *, for addressing all the element ID's on the page at once, like if you want to hide all layers at once. For example:

document.getElementById('*').style.visibility = 'hidden';
No. You only get one element with getElementById, so using a wildcard
doesn't make sense. Even if it returned more than one element, you can't
use .style.visiblity on the collection and hope it affects the contents.
I know the above doesn't work but you get what I'm driving at right? Is
there anything like that for that method or in javascript in general?


What you can use instead is:

var elems = document.getElementsByTagName("*"); // yes, wildcards do

exist for (var i=0;i<elems.length;i++) {
if ( .... elems[i] .... ) { // you probably don't want to hide *all* elements elems[i].style.visibility="hidden";
}
}

thanks a lot. Why is it that I don't see the getElementByTagName method in
the javascript reference in the newest version of dreamweaver (mx 2004)? Is
it really new or something?
Jul 20 '05 #5
"TheKeith" <no@spam.com> writes:
Why is it that I don't see the getElementByTagName method in the
javascript reference in the newest version of dreamweaver (mx 2004)?
I'll blame whoever made dreamweaver. But I do that already, having seen
the Javascript it embeds in the pages it makes.
Is it really new or something?


The getElementsByTagName function was part of the W3C DOM 1, which was
made a recommendation in October 1998. Ofcourse, browsersupport lacked
behind, and Windows IE only supported it from version 5.0 (March
1999), Opera from version 5 (December 2000), and Mozilla/Netscape 6+
from the beginning (no exact date, Netscape 6 was based on a pre-1.0
version of Mozilla, and was released in November 2000, but people had
been using builds of Mozilla before that).

/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 #6

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

Similar topics

1
by: Generic Usenet Account | last post by:
Here's the requirement that I am trying to satisfy: Handle wildcards in STL such that the wildcard entry is encountered before non-wildcard entries while traversing containers like sets and...
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like this: *somestring* The purpose is to match any...
3
by: Adam | last post by:
Its my understanding that in asp.net 2.0 you can write an httpmodule that will acts as a wildcard handler and pass requests on to the proper engine, for instance, asp or perl for example, In the...
2
by: Ken Yee | last post by:
First a little background: I've written an httphandler to handle wildcard extensions (i.e., I want to handle all URLs that come in rather than just URLs w/ a specific file extension so I can give...
7
by: SlimFlem | last post by:
I have searched hard for 2 days on this and keep hitting a wall. I have a custom IHttpHandler setup to do Url mappings to prop up some old Urls for our site. I have also created a wildcard...
2
by: Jan Kucera | last post by:
Hi, I have virtual MyFolder/* and MyFolder/MySubFolder/* mapped to an httphandler in the web.config file and all works perfectly on the asp.net development server. However on the IIS6/Win2003 I'm...
6
by: Jan Kucera | last post by:
Hi, does anybody know about wildcard mapping ASP.NET 2 in IIS6? Any tutorial? Thanks, Jan
1
by: Lucvdv | last post by:
In my assembly.vb files, I'm using the revision/build wildcard style: <Assembly: AssemblyVersion("3.0.*")> <Assembly: AssemblyFileVersion("3.0.*")> This onkly seems to work in projects that...
1
by: munkee | last post by:
Im back... with more ActiveDirectory questions. Firslty I will show you my output: Output 1 - Search based on department name: The filter string:...
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...
1
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...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.