需要使用jQuery.find来查找具有特定样式的元素 [英] Need to use jQuery.find to find element with specific style
问题描述
我想我在这里正确的道路.. 。(但不是那里):
pre $ j $ jQuery('#adminMenu li')。find(ul)。css('display );
对于高级用户:我怎样才能找到并改变一行的样式?
这是棘手的陈述,但是可以解决的其他方式。最简单的是:
$(#adminMenu li ul:visible)。hide();
假设项目是隐藏或不隐藏的。当然,考虑到你想隐藏他们,为什么不只是:
$ $ $ $#adminMenu li ul。hide( );
尽量避免直接更改CSS样式。这是有问题的。这很难扭转,而你发现很难搜索。改为使用类:
#adminMenu li ul {display:none; }
ul.block {display:block; }
与:
$(#adminMenu li ul)。removeClass(block);
或
$(#adminMenu li ul.block)。removeClass(block);
Right... I need to find all < ul style="display: block;"> elements, so that I can set it do display:none.
I think I'm on the right path here... but not quite there:
jQuery('#adminMenu li').find("ul").css('display');
For advance users: how can I find and change the style with one line?
That's tricky as stated but is solvable other ways. The easiest is:
$("#adminMenu li ul:visible").hide();
assuming items are either hidden or not. Of course, considering you want to hide them all why not just:
$("#adminMenu li ul").hide();
Try and avoid changing CSS style directly. It's problematic. It's hard to reverse and as you're discovering hard to search for. Use a class instead:
#adminMenu li ul { display: none; }
ul.block { display: block; }
with:
$("#adminMenu li ul").removeClass("block");
or
$("#adminMenu li ul.block").removeClass("block");
这篇关于需要使用jQuery.find来查找具有特定样式的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!