2

I can access my CSS with JQuery like so:

alert($(".sliver1").css('width'));

The console reports that the .css property of "this" is undefined:

var sliver = "sliver";

        $("section").each(function()
        {
            if(this.className.indexOf(sliver) !== -1)
            {
                alert(this.css('width'));
            }
        });

How can I access the CSS of the elements found?

Thank you.

4

2 に答える 2

2

jQueryの使い方が.css間違っています。これを使って:

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

;when 内に when をドロップしalert()ます。必要に応じてプロパティwidthを変更します。

を使用する場合、は jQuery メソッドであるため、.each()jQuery セレクターが必要です。$(this).css('width').css()

于 2013-04-13T16:25:55.027 に答える