【发布时间】:2013-09-09 14:45:22
【问题描述】:
我正在使用find(sel) 更改与sel 匹配的所有元素的css 属性:如果该元素设置了position,那么它应该得到position,否则它应该得到relative。
$("#mydiv").find("form").css({ "z-index": 2, "position": jQuery(this).css("position") || "relative", "background-color": "green" })
不工作.. 最好的方法来完成这个?
【问题讨论】:
-
默认不都是
static吗?他们会有一个位置值,所以也许你应该检查它是否是静态的。 -
是的,
return (jQuery(this).css("position") != "static") ? jQuery(this).css("position") : "relative"
标签: jquery reference find element