This is the self-defined jQuery function
$.fn.wider = function(callback) {
$(this).animate({width: 500}, function() {
callback();
});
};
Call the function
$('#div').wider(function() {
console.log('div resizing done');
// $(this) refers to window instead of $('#div')
$(this).css({background: '#f00'});
});
so how can I use $(this) like in the click funciton below?
$('#div').click(function() {
console.log('div clicked');
// $(this) refers to $('#div')
$(this).css({background: '#f00'});
});
Use
Function.apply.A slightly more general implementation: