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

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

问题描述

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天全站免登陆