JQuery: referring to the right "this"
I'm trying to write a very simple plugin that on anchor mouseover increases the respective anchor text size and on mouseout re开发者_如何学编程moves the anchor. The problem is that I can't get the right "this". So I have:
(function($){
$.fn.extend({
//function name
textOverlay : function(){
//return
return this.each(function(){
var cucu = $(this);
$(this).hover(
function(){
cucu.css({'font-size':'20px'});
},
function(){
cucu.remove();
}
);
});
}
});
})(jQuery);
and I call it like this:
$(document).ready(function(){
$('a').thiseOverlay();
});
I guess I should use something like .call()
or .apply()
, but I'm not sure how, I couldn't find good resources.
It should work if you simply call $('a').textOverlay()
instead of $('a').thiseOverlay()
what you did.
精彩评论