$.fn.hover: use shortcut for adding/removing a class
Hi everyOne,
Just my 2 coins about $.fn.hover function:
As i often use this function to add & remove class (basically, due to
ie lack of css2 support), I thought it could be usefull to add a
shortcut version of the $.fn.hover function.
My hacked version:
$.fn.hover =
function(over, out) {
var class = typeof over == 'string' && over || over == undefined &&
'hover';
return this.bind('mouseenter',
class && function(){$(this).addClass(class);} || over )
.bind('mouseleave',
class && function(){$(this).removeClass(class);} || out);
}
So we could use:
$('selector').hover() equal $('selector').hover('hover'): add & remove
'hover' class to matched elements
$('selector').hover('mycustom'): add & remove 'mycustom' class to
matched elements
$('selector').hover(function(){...},function(){...}): the usual way to
use $.fn.hover still works.
I didn't know where to propose this hack, i think the dev mailing list
is a good place to start.
What do you think of that shortcut?
I think this handy shortcut could be added in core, but if not, at
least as a plugin.
Feedback are welcome!