Search code examples
javascriptjquery-pluginsjqueryjquery-hover

Trying to extend jQuery


I'm extending jQuery with a function I wrote called bindHoverEvents:

$.fn.bindHoverEvents = function () {
    this.hover ( function () {
            // mouseenter function
        }, function () {
            // mouseleave function
        }
     );
};

The problem is that when I call this function on an object, the hover events are not bound to it:

$(object).bindHoverEvents();

I know bindHoverEvents is getting called, because when I put an alert at the beginning of the function, right before this.hover(...), the alert shows up. However, when I put the same alert inside of the mouseenter function, it doesn't show up when I hover over the object. Any ideas why?


Solution

  • Just figured it out. When I called $(object).bindHoverEvents(), object was just an instance of a javascript object, not an element in the DOM.

    Woops...