jQuery选择具有特定CSS的元素
我正在尝试向所有具有position:fixed set的元素添加一些jQuery代码。 这种事情有可能吗? 如果有的话会非常有用,所以我不需要经历所有代码和额外的类来修复对象。
这个应涵盖所有情况:
$('*').filter(function() { return $(this).css("position") === 'fixed'; });
没有qwertymk的答案快,但如果css属性inheritance自另一个规则,也可以工作,如此处所示。
比科林的回答更快更安全:
$('*').filter(function(){ return this.style && this.style.position === 'fixed'; });
有关jQueryfilter的更多信息()
如果您只检查display: none
和其他display
属性。 您可以使用CSS选择器:visible
在您通常的jQuery选择中:visible
,如下所示:
$('.items:visible')
或者选择隐藏的元素:
$('.items:hidden')