jQuery选择具有特定CSS的元素 [英] jQuery Select Elements with a certain CSS
本文介绍了jQuery选择具有特定CSS的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向所有具有position:fixed设置的元素添加一些jQuery代码.这样的事情可能吗?如果有的话,这将非常有帮助,因此我不必遍历所有代码和固定对象的额外类.
I'm trying to add a bit of jQuery code to all elements that have position:fixed set on them. Is this sort of thing possible? It would be very helpful if there is, so I don't have to go through all my code and an extra class to the objects that are fixed.
推荐答案
此方案应涵盖所有情况:
This one should cover all cases:
$('*').filter(function() {
return $(this).css("position") === 'fixed';
});
不如qwertymk的回答快,但是如果css属性是从另一个规则继承的,也可以工作,如所示这里.
Not as fast as qwertymk's answer, but also work if the css property is inherited from another rule, as demonstrated here.
这篇关于jQuery选择具有特定CSS的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文