我可以像JQuery一样访问我的CSS:
alert($(".sliver1").css('width'));
控制台报告“this”的.css属性未定义:
var sliver = "sliver";
$("section").each(function()
{
if(this.className.indexOf(sliver) !== -1)
{
alert(this.css('width'));
}
});
如何访问找到的元素的CSS?
谢谢。
答案 0 :(得分:2)
您正在使用jQuery的.css
错误。使用此:
$("section").css('width');
在;
内放下alert()
。根据需要更改属性width
。
使用.each()
时,您需要$(this)
的jQuery选择器.css('width')
,因为.css()
是一个jQuery方法。
答案 1 :(得分:1)
尝试$(this).css('width');应该工作。