Solved

getElementsByClassName on prototype

Posted on 2009-04-02
1
176 Views
Last Modified: 2012-05-06
Hi there,
Completely stuck with a trivial issue i suppose.
I use the prototype library
I have an element and want to get all its child elements with class 'rooms' and do something with each.
What i do is the following code and i get an error el.getElementsByClassName(".rooms").each is not a function
el.getElementsByClassName(".rooms") return an HTMLcollection...How on earth can i manipulate the elements of this collection?

thanks

el.getElementsByClassName('.rooms').each(function(e){

				//do something

			});

Open in new window

0
Comment
Question by:ioustinos_sarris
1 Comment
 
LVL 10

Accepted Solution

by:
cyberstalker earned 500 total points
ID: 24053028
You can loop through all the elements with a for loop
var elements = el.getElementsByClassName('.rooms');
 

for (var i = 0; i < elements.length; i++)

{

    // do something with elements.item(i)

}

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now