470,647 Members | 1,313 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

Selecting all elements with same class name

I have multiple elements with the same class ID. I want to Hide them
all, but I only know how to select one element at a time, e.g.
Element.hide('element). How can I do this to multiple elements with the
same id or class name?

PS. I have access to prototype....

Dec 8 '06 #1
7 3307
ASM
eg****@gmail.com a écrit :
I have multiple elements with the same class ID.
with the same class or the same id ?
it is absolutely forbiden to have more than ONE element with same id !
I want to Hide them
all, but I only know how to select one element at a time, e.g.
Element.hide('element). How can I do this to multiple elements with the
same id or class name?
No you can't with same id because id is unique on a same page :-(

If elements are with same class :

You can create a special class for the body which will say to this class
: hop! hide !

<style type="text/css">
..normal { color: blue }
..hid .normal { visibility: hidden }
</style>
<script type="text/javascript">
function hidShw(){
document.body.className = document.body.className==''? 'hid' : ''; }
</script>
<div class="normal">text 1</div>
<div>
<p>text 2</p>
<p class="normal">text 3</p>
</div>
<p><button onclick="hidShw()">Hide/Show blue elements</button></p>
<h3>text 4</h3>
<h2 class="normal">text 5</h2>

PS. I have access to prototype....
why not a panzer division ?
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 8 '06 #2
ASM wrote :
eg****@gmail.com a écrit :
>I have multiple elements with the same class ID.
with the same class or the same id ?
it is absolutely forbiden to have more than ONE element with same id !
>I want to Hide them
all, but I only know how to select one element at a time, e.g.
Element.hide('element). How can I do this to multiple elements with the
same id or class name?
No you can't with same id because id is unique on a same page :-(

If elements are with same class :

You can create a special class for the body which will say to this class
: hop! hide !

<style type="text/css">
.normal { color: blue }
.hid .normal { visibility: hidden }
</style>
<script type="text/javascript">
function hidShw(){
document.body.className = document.body.className==''? 'hid' : ''; }
</script>
<div class="normal">text 1</div>
<div>
<p>text 2</p>
<p class="normal">text 3</p>
</div>
<p><button onclick="hidShw()">Hide/Show blue elements</button></p>
<h3>text 4</h3>
<h2 class="normal">text 5</h2>

>PS. I have access to prototype....
why not a panzer division ?
YOu can also use :
getElementByClassName :)

PS: I you have the panzer division you're talking abut, let me hear aboutit, I
may need one ;)

--
Naixn
http://fma-fr.net
Dec 9 '06 #3
ASM
naixn a écrit :
>
YOu can also use :
getElementByClassName :)
don't know what it is
PS: I you have the panzer division you're talking abut, let me hear
about it, I
may need one ;)
here you are :
http://www.google.com/search?q=panzer
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 9 '06 #4
ASM wrote :
naixn a écrit :
>>
YOu can also use :
getElementByClassName :)
don't know what it is
Forget it... I said this out of the blue, and in fact, that was something
I was in a script. nothing official in Javascript...
>PS: I you have the panzer division you're talking abut, let me hear
about it, I
may need one ;)
here you are :
http://www.google.com/search?q=panzer
Do you deliver? :p

--
Naixn
http://fma-fr.net
Dec 9 '06 #5
ASM
naixn a écrit :
ASM wrote :
>naixn a écrit :
>>>
getElementByClassName :)

don't know what it is

Forget it... I said this out of the blue,
I understood but now you have to give your function getElementByClassName()
for OP can follow, no ?

Do you deliver? :p
as soon as I'll've found the package
(how many dozens ?)
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 9 '06 #6
naixn wrote on 09 dec 2006 in comp.lang.javascript:
YOu can also use :
getElementByClassName :)
You are missing an "s":

getElementsByClassName()

<http://javascript.about.com/library/bldom08.htm>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 9 '06 #7
ASM
Evertjan. a écrit :
>
getElementsByClassName()

<http://javascript.about.com/library/bldom08.htm>
Interesting,

Now we have one panzer :-)
and next step ?
(lost my manual : where is the button to fire ? )

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 9 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by thomas | last post: by
5 posts views Thread by Axial | last post: by
4 posts views Thread by Chris Jones | last post: by
2 posts views Thread by areef.islam | last post: by
1 post views Thread by jdhcards | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.