1.

Create A Plugin That Would Add And Remove A Class On Hover?

Answer»

The plugin can be considered to be simply a new method that can be used by a user to extend the prototype object of a jquery. A plugin performs some ACTIONS on a COLLECTION of elements. Each method that comes with the jquery core can be considered to be a plugin.

The code for CREATING a plugin that would add and remove a CLASS on hover would be as follows:

(function($){ $.fn.hoverClass = function(c) { return this.hover( function() { $(this).toggleClass(c); } ); }; })(jQuery); // using the plugin $('li').hoverClass('hover');

The plugin can be considered to be simply a new method that can be used by a user to extend the prototype object of a jquery. A plugin performs some actions on a collection of elements. Each method that comes with the jquery core can be considered to be a plugin.

The code for creating a plugin that would add and remove a class on hover would be as follows:



Discussion

No Comment Found