Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding multiple objects with the same id property

Status
Not open for further replies.

Phil79

Technical User
Jun 5, 2002
64
0
0
GB
Hi,

I'm having a bit of trouble with a script I'm trying to write. I'm making a folding menu using <UL> tags which all have that same ID ('foldinglist'). How can I make all of the <UL> tags with the ID 'foldinglist' hide at the same time. This is what I'm trying to use, but I guess it's wide of the mark.
Code:
HideList = document.getElementsByTagName(&quot;ul&quot;);
HideList['foldinglist'].style.display==&quot;none&quot;
Do I suck or am I close? Thanks in advance.

Phil

PS: Can anyone point me at some good documents about document.getElementsByTagName and document.getElementsByID? Thanks.
 
HideList = document.getElementsByTagName(&quot;ul&quot;);

for (x=0; x<HideList.length; x++){
if (HideList[x].id == &quot;foldingList&quot;){
HideList[x].style.display = &quot;none&quot;
}
} Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Phil,

you should never use the same id twice in a document - the definition of an id is a unique identifier. if you want to make a group of like elements, give them the same name.




=========================================================
while (!succeed) try();
-jeff
 
Thank you both very much for your help,

Jeff, this may be a vague qusetion, but what is the differance between name and id? Is is simply that name is not individual and id is?
 
correct - name can identify one or more elements, accessible by array index notation if more than 1 element by the same name:

<input name=&quot;color&quot; value=&quot;R&quot;/>
<input name=&quot;color&quot; value=&quot;G&quot;/>
<input name=&quot;color&quot; value=&quot;B&quot;/>

here, color[1] == &quot;G&quot;


an &quot;id&quot; should only be used once in a document...use an id to uniquely identify an element so you can perform actions on it etc...

<div id=&quot;menu&quot;>MENU</div>

document.getElementById(&quot;menu&quot;).style.display = &quot;none&quot;;


=========================================================
while (!succeed) try();
-jeff
 
Thanks a lot, you've been a big help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top