找到position:attribute的元素 [英] find elements with position:attribute

查看:94
本文介绍了找到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屋!

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