Create a plugin that would add and remove a class on hover?
Submitted by: MuhammadThe 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');
Submitted by: Muhammad
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');
Submitted by: Muhammad
Read Online JQuery Programmer Job Interview Questions And Answers
Top JQuery Programmer Questions
☺ | What are jQuery Selectors? Give some examples? |
☺ | How to get the direct parent of an element using jQuery? |
☺ | How to set the style property of an element using jQuery? |
☺ | How to get the height of an element using jQuery? |
☺ | Explain the common methods of sending a request to a server? |
Top Scripting language Categories
☺ | AngularJS Interview Questions. |
☺ | Ext-JS Interview Questions. |
☺ | Dojo Interview Questions. |
☺ | Expert Developer JavaScript Interview Questions. |
☺ | SWFObject Interview Questions. |