开发者

Access $(this) from a .toggle

开发者 https://www.devze.com 2023-03-14 17:55 出处:网络
i have a toggle function like this ( really short just for the Q purpose ): $(\'element\').toggle( function() {开发者_开发技巧

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

精彩评论

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