开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜