开发者

Access $(this) from a .toggle

i have a toggle function like this ( really short just for the Q purpose ):

$('element').toggle(
    function() {开发者_开发技巧
        alert($(this).offset.top);
    },
    function() {

    }
)

as explained in the code, i cant access the $(this) object values like $(this).offset.top for some reason. please help.


You need to call the offset() function in order to retrieve the top property:

$('div').toggle(
    function() {
        alert($(this).offset().top);
    },
    function() {

    }
);

example: http://jsfiddle.net/niklasvh/6abGk/


offset is a function. That should be

alert($(this).offset().top);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜