473,320 Members | 2,041 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,320 software developers and data experts.

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 38801
<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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.