开发者

Referring to "this" without using .each()

开发者 https://www.devze.com 2023-04-12 12:57 出处:网络
I have an element $myElement that I want to refer to using this inside .css() call. Specifically, I tried to change the CSS property someCssProperty to $myElement.myProperty naively:

I have an element $myElement that I want to refer to using this inside .css() call. Specifically, I tried to change the CSS property someCssProperty to $myElement.myProperty naively:

$myElement.css(someC开发者_如何学GossProperty, this.myProperty);

Is there a way of having a working this without using the cumbersome .each()?


css takes a function as a parameter which you can use:

$myElement.css(someCssProperty, function(index, value) {
    return this.myProperty;
});

The callback also receives the index in the set and the old value as parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消