Skip to main content

Bug Tracker

Side navigation

#4919 closed feature (wontfix)

Opened July 18, 2009 01:39PM UTC

Closed January 13, 2011 09:07PM UTC

Add a hoverClass method

Reported by: joern Owned by:
Priority: low Milestone: 1.next
Component: attributes Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:
Description

The following 5 lines are repeated across applications and plugins again and again. I propose to add a plugin method to jQuery core to reduce these to simple one liners:

$(".selector").hover(function() {
  $(this).addClass("class");
}, function() {
  $(this).removeClass("class");
});

Plugin method and usage:

$.fn.hoverClass = function(hoverClass) {
  return this.hover(function() {
    $(this).addClass(hoverClass);
  }, function() {
    $(this).removeClass(hoverClass);
  });
});
$(".selector").hoverClass("class");
Attachments (0)
Change History (6)

Changed July 20, 2009 02:23AM UTC by scottgonzalez comment:1

Changed October 22, 2010 06:23PM UTC by rwaldron comment:2

component: coreattributes
keywords: → event attributes
milestone: 1.41.5
priority: majorlow
status: newopen

Changed November 13, 2010 11:10PM UTC by anonymous comment:3

This is pretty much duplicating the functionality already available in CSS with :hover pseudo-classes.

Changed December 14, 2010 11:26AM UTC by arshadabbas comment:4

You can use:

$("#div1").hover(function(){

$("#div1").toggleClass("bgcolor");

});

Instead of:

$("#div1").toggleClass("bgcolor");

Changed January 12, 2011 02:05AM UTC by dmethvin comment:5

keywords: event attributesneedsreview
milestone: 1.51.next

Changed January 13, 2011 09:07PM UTC by addyosmani comment:6

keywords: needsreview
resolution: → wontfix
status: openclosed

Following on from Scott_Gonzalez, the dev thread above and here point to there being a group consensus that this wouldn't really be that useful. We're closing as wontfix for now, unless there is a massive change in group thinking on why this shouldnt be the case.