使用JQuery迭代样式数据

时间:2013-04-13 16:22:43

标签: javascript jquery css

我可以像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?

谢谢。

2 个答案:

答案 0 :(得分:2)

您正在使用jQuery的.css错误。使用此:

$("section").css('width');

;内放下alert()。根据需要更改属性width

使用.each()时,您需要$(this)的jQuery选择器.css('width'),因为.css()是一个jQuery方法。

答案 1 :(得分:1)

尝试$(this).css('width');应该工作。