Reputation: 1334
I want to set #first
and #second
as $(this) to use element id only when function is calling.
is it possible?or any other way?
(function( $ ){
$.fn.showCircle = function(top,right) {
$timeout(function () {
$(this).css({
right:right,
top:top,
});
});
};
})( jQuery );
$('#first').showCircle(300,200);
$('#second').showCircle(800,200);
Upvotes: 1
Views: 71
Reputation: 1334
thanks to @panther comment inside $timeout
this refer to window
so as @panther said I changed the function :
(function ($) {
$.fn.showCircle = function (top, right) {
var self = this;
$timeout(function () {
$(self.selector).css({
right: right,
top: top,
});
});
};
})(jQuery);
Upvotes: 0
Reputation: 1
You can use jQuery.proxy()
to set this
at a function call
$timeout($.proxy(function () {
$(this).css({
right:right,
top:top,
});
}, this));
Upvotes: 2