Alex Rivera | Logout

how to loop over the child divs of a div and get the ids of the child divs?

Asked 2012-07-02T09:51:06.537
20

I have a div with id test

and through the foreach loop I am creating some inner divs inside the test div. So it becomes like this.

<div id="test">
<div id="test-1"></div>
<div id="test-2"></div>
<div id="test-3"></div>
<div id="test-4"></div>
</div>

I am getting the parent div id "test" in the javascript function. Now I want to loop through the inner divs(child divs) of the test div and get the id of the each div one by one and style them through javascript.

Any Idea about this?

Edit
Report

1 Answer

0

You can use

$('[id^=test-]')

and each()

this way for example :

$('[id^=test-]').each(function(){
    var atId = this.id;
    // do something with it
});​
answered 2012-07-02T09:55:08.637

Your Answer