Skip to content

Instantly share code, notes, and snippets.

@kgn
Created October 14, 2010 09:36
Show Gist options
  • Select an option

  • Save kgn/625948 to your computer and use it in GitHub Desktop.

Select an option

Save kgn/625948 to your computer and use it in GitHub Desktop.
Assign a class to an element, or a child of the element on mouse over.
/*
Assign a class to an element, or a child of the element on mouse over.
$('#apps .header').rollover({
'className' : 'glow',
'childSelector' : 'h2',
});
*/
(function($){
$.fn.rollover = function(options){
options = $.extend({
'className': null,
'childSelector': null
}, options);
//if there is no class name there is
//no point of going any further
if(options.className === null){
return this;
}
return this.each(function(){
var item = this;
if(options.childSelector){
item = $(this).children(options.childSelector)[0];
}
if(item){
$(this).hover(function(){
$(item).addClass(options.className);
},function(){
$(item).removeClass(options.className);
});
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment