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);
精彩评论