Bernd Matzner wrote:
Hi Eridius,

yes, "this" refers to the object passed to the plugin, in your case

$('#hover_menu').hover_menu();
which would be shorter than
$('div[id=hover_menu]').hover_menu()


(function($)
{
    $.fn.hover_menu  = function(){
        $(this).children('ul').children('li').hide();
    };
})( jQuery );

I assume that in your div you have an unordered list, so with this
code you would traverse to any <li> tags in any unordered list within
your div.
Does that help?


Inside the plugin method "this" is already a jQuery object, thus you don't have to write $(this), $(self) or whatnot. That'll copy the whole jQuery object and is an unneeded overhead. Simply use "this":

(function($) {
    $.fn.hover_menu = function() {
        this.children('ul').children('li').hide();
    };
})(jQuery);

And you usually shouldn't forget to maintain chainability by returning the object:

(function($) {
    $.fn.hover_menu = function() {
        this.children('ul').children('li').hide();
        return this;
    };
})(jQuery);


--Klaus


Reply via email to