Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

getElementsByClassName on prototype

Posted on 2009-04-02
1
Medium Priority
?
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
cyberstalker earned 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

722 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