找到position:attribute的元素 [英] find elements with position:attribute
问题描述
我会尝试在页面中找到所有绝对元素;使用jQuery我虽然它会像
I would try to find all "absolute" elements in my page; with jQuery I though it would be something like
$('[position="absolute"]')
但是在ff 10.0.2我找不到元素...
but on ff 10.0.2 I cannot find an element...
另外,我无法在 http://api.jquery.com/attribute-equals-selector上运行exaple代码/
这个语法有问题吗?
Also, I cannot run the exaple code on http://api.jquery.com/attribute-equals-selector/ Is there something wrong on this syntax?
推荐答案
你可以用 filter()
$('*').filter(function(){
var position = $(this).css('position');
return position === 'absolute';
});
您不能使用属性等于选择器,因为该选择器将搜索具有名为position的属性的元素等于绝对像这样
You can't use attribute equals selector because because that selector would search elements with an attribute called position that equals absolute like this
<div position="absolute">
但在您的情况下,仓位是css属性
but in your case position is a css property
这篇关于找到position:attribute的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!