简体   繁体   English

jquery - slideDown每个父ul

[英]jquery - slideDown each of parent ul

I have a multilevel menu. 我有一个多级菜单。 Each of level is a list with ul-tag. 每个级别都是带有ul-tag的列表。 Each point of the menu is li-tag. 菜单的每个点都是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'. 但我得到一个错误'Uncaught TypeError:parent.slideDown不是一个函数'。 And when I try to print a parent in console, I get the raw html. 当我尝试在控制台中打印父级时,我会获得原始的html。 How can I get an access to the single parent inside each to make a slideDown? 如何访问每个内部的单个父级以进行slideDown? Or slide down all parents in any ways. 或以任何方式滑下所有父母。

parent is the reference to a DOM element, not a jQuery object. parent是对DOM元素的引用,而不是jQuery对象。 (That is simply how .each works.) (这就是.each的工作原理。)

You need to wrap it in $() before you can call jQuery methods on it. 您需要将它包装在$()然后才能在其上调用jQuery方法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM