Search code examples
jqueryobjecteachchildren

Jquery object as variable, each of its childs


I want to make some jquery slider function. Im using code:

var parentElement = $('#slidercontent');

In this object i have a ul element with li elements (childrens). I want to make a each function and get all childrens of this element.

I try some combinations for ex:

parentElement.each(function(){ 
console.log('its a li!');
});

parentElement.children().each(function(){ 
console.log('its a li!');
});

but this not working effective.


Solution

  • $(function(){
        var parentElement = $('#slidercontent');
        parentElement.children().each(function(){ 
           //use $(this).children() to get children's children
           console.log($(this).children());
       });
    });
    

    DEMO: http://jsfiddle.net/dirtyd77/VfD52/