无法删除jQuery变量中的嵌套列表 [英] not able to remove nested lists in a jQuery variable
问题描述
我有一个嵌套的oredered列表,正在使用此代码制作动画...
I have a nested oredered list which i m animating using this code...
var $li = $("ol#update li");
function animate_li(){
$li.filter(':first')
.animate({
height: 'show',
opacity: 'show'
}, 500, function(){
animate_li();
});
$li = $li.not(':first');
}
animate_li();
现在我不想不显示或动画化ols中的嵌套列表(ol s)或lis
now i want not to show or animate the nested lists(ol s) or the li s in the ols
在此处
我的ol的结构是
<ol>
<li class="bar248">
<div class="nli">
<div class="pic">
<img src="dir/anonymous-thumb.png"alt="image" />
</div>
<div align="left" class="text">
<span>
<span class="delete_button"><a href="#" id="test" class="delete_update">R</a></span>
test shouted <span class="timestamp"> 2010/02/24 18:34:26 </span> <br />
this
</span>
</div>
<div class="clear"></div>
</div>
<div class="padd">
</div>
<ol class="comment">
<li>
<div>Testing </div>
</li>
<li>
<div>Another Test </div>
</li>
</ol>
</li>
</ol>
我可以使用此代码隐藏嵌套的ols ...
I m able to hide the nested ols using this code...
$("ol#update li ol").hide();
但是尽管它们被隐藏了,但仍在为它们设置动画上花费时间
But still time is being consumed in animating them although they are hidden
我无法使用此代码删除嵌套的Lis
I m not able to remove the nested li s using this code
var $li = $("ol#update li").not("ol#update li ol");
$li = $li.not("ol#update li ol");
在此处
任何帮助
感谢
Pradyut
thanks
Pradyut
推荐答案
您是否尝试过像这样设置原始列表:
Have you tried setting up your original list like this:
var $li = $("ol#update > li");
那只会得到<ol id="update">
列表的直接子元素<li>
.
That will get only the <li>
elements that are direct children of the <ol id="update">
list.
如果您已经设置了$li
,而没有使用>",则可以使用过滤器"从该列表中删除嵌套"的<li>
元素:
If you've already got $li
set up without the ">", then you can remove the "nested" <li>
elements from that list using "filter":
var $li = $('ol#update li'); // gets all <li> elements, even the nested ones
// ...
var $notNested = $li.filter('ol#update > li');
// or, if you prefer,
var $notNested = $li.filter(':not(ol#update li ol li)');
这篇关于无法删除jQuery变量中的嵌套列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!