Skip to content Skip to sidebar Skip to footer

Using Jquery .find() To Get Children

I have the following markup:

Solution 1:

$('#items').find('.item_box').each(function(){
    alert($(this).attr('id'));
});

Solution 2:

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'));
});

Solution 3:

  1. Search by Class 'item_box'
  2. iterate them to collect ids

$(function(){

    var child = $('#items').find('div.item_box');

    var idArray = newArray();

    if(child.length){

        $.each(child,function(i,entry){

            idArray.push($(this).attr('id'));

        });

    }

    console.log(idArray);

});​

Fiddle Assistance : http://jsfiddle.net/FFp4B/

Post a Comment for "Using Jquery .find() To Get Children"