需要使用jQuery.find来查找具有特定样式的元素 [英] Need to use jQuery.find to find element with specific style

查看:1736
本文介绍了需要使用jQuery.find来查找具有特定样式的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正确...我需要找到所有< p>我可以设置它显示:无。



我想我在这里正确的道路.. 。(但不是那里):

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆