jQuery: The Write Less, Do More JavaScript Library

Ticket #294 (closed feature: worksforme)

Opened 2 years ago

Last modified 1 year ago

hoverClass

Reported by: giel.berkers@… Assigned to: anonymous
Type: feature Priority: minor
Milestone: Component: event
Version: Keywords: hover hoverclass mouseover mouseout
Cc: Needs:

Description

It would be nice if there was a feature called hoverClass. Which would simply add a class on a mouseover event and remove it on mouseout. The source would then look like something like:

$("h3").hoverClass("over");

This offcourse would add the class "over" to the h3-element on mouseover and remove it on mouseout.

Attachments

Change History

Changed 2 years ago by joern

  • status changed from new to closed
  • resolution set to worksforme

This can be easily added if needed, try this (tested):

jQuery.fn.hoverClass = function(value) {
  return this.hover(function() {
    jQuery(this).addClass(value);
  }, function() {
    jQuery(this).removeClass(value)
  });
};
Note: See TracTickets for help on using tickets.