Forum Moderators: open

Message Too Old, No Replies

grab all elements of the same type from a document

         

Rhenan

11:32 pm on Nov 13, 2004 (gmt 0)

10+ Year Member



I have a page that uses multiple <SPAN> tags, and each one has a different name so that I can show/hide them individually. I'd also like to create a script that will hide them all at the same time, but as the document will be dynamically generated I won't know all the names.

Is it possible, in Javascript, to grab all the <SPAN> tags and put them into an array? I know of my <SPAN>s had the same name I could use getElementsByName, but as they are all using different names, this approach won't work.

What I need is something like (and this is a made up method I'm sure, but servers the example purpose)..

getElementsByType("SPAN")

or a bunch of code that will basically give me the same results.

thanks for reading and to anyone that can help.

adni18

11:37 pm on Nov 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.getElementsByTagName('span')

Rhenan

1:25 am on Nov 14, 2004 (gmt 0)

10+ Year Member



Wonderful! Thanks so much.. I was hunting the Web with google and couldn't find anything like that.

Really appreciate the help :)

adni18

1:41 am on Nov 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any time! By the way, welcome to WebMaster World!