views:

39

answers:

2

I have the following markup:

<div id="items">
   <div class="item">
     <div class="item_box" id="id_1">
       <div class="one" id="one"></div>
     </div>
    </div>
   <div class="item">
     <div class="item_box" id="id_2">
       <div class="one" id="two"></div>
     </div>
    </div>
   <div class="item">
     <div class="item_box" id="id_3">
       <div class="one" id="three"></div>
     </div>
    </div>
 </div>

Basically, I want to be able to loop through and get the id value in the item_box class.

Here's the code I'm trying to use:

$('#items').find(/[id_]/).each(
      function(){
         alert($(this).attr('id'));
      });

This doesn't work though... I've tried using .children, however that won't go as deep as these are nested.

Any ideas?

Thanks!

+2  A: 
$('#items').find('.item_box').each(function(){
    alert($(this).attr('id'));
});
PetersenDidIt
A: 

You were very close. Here's your code, modified to search for children of #items which have an id that starts with id_

$('#items *[id^=id_]').each(function(){
    alert($(this).attr('id'));
});
artlung