Search code examples
javascriptjqueryparentslidedown

jquery - slideDown each of parent ul


I have a multilevel menu. Each of level is a list with ul-tag. Each point of the menu is li-tag.

I want to slide down all of parent uls of the current point of the menu when loading the page.

Now I do the next:

var parents = selector.parents('ul');

parents.each(function(index, parent){
    parent.slideDown();
});

But I get an error 'Uncaught TypeError: parent.slideDown is not a function'. And when I try to print a parent in console, I get the raw html. How can I get an access to the single parent inside each to make a slideDown? Or slide down all parents in any ways.


Solution

  • parent is the reference to a DOM element, not a jQuery object. (That is simply how .each works.)

    You need to wrap it in $() before you can call jQuery methods on it.

    parents.each(function(index, parent){
        $(parent).slideDown();
    });