-1

i'm just creating a grid system for responsive web design and my code (simplified) looks like this:

<div id="row1">
<div class="type_3">
</div>
<div class="type_1">
</div>
<div class="type_2">
</div>
<div class="type_2">
</div>
</div>

Now I want to get the names of the classes and the order of the elements, that are direct children of .row1 as an array or string (or similar) in js. The order is very important in this case. Any ideas? Thanks in advance, JBG

  • possible duplicate of [How to get child element by class name?](http://stackoverflow.com/questions/12166753/how-to-get-child-element-by-class-name) – dsgriffin May 12 '13 at 11:47

1 Answers1

0

Iterate over the children of #row1 node:

var children = document.getElementById("row1").children;
for (var i = 0; i < children.length; ++i) {
    alert(children[i].className);
}

alert is just for a quick demo, do anything you want inside the loop. Here is a jsfiddle.

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80