Bug Tracker

Opened 10 years ago

Closed 9 years ago

#4919 closed feature (wontfix)

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");

Change History (6)

comment:1 Changed 10 years ago by scottgonzalez

comment:2 Changed 9 years ago by Rick Waldron

Component: coreattributes
Keywords: event attributes added
Milestone: 1.41.5
Priority: majorlow
Status: newopen

comment:3 Changed 9 years ago by anonymous

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

comment:4 Changed 9 years ago by arshadabbas

You can use:

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

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

});

Instead of:

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

comment:5 Changed 9 years ago by dmethvin

Keywords: needsreview added; event attributes removed
Milestone: 1.51.next

comment:6 Changed 9 years ago by addyosmani

Keywords: needsreview removed
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.

Note: See TracTickets for help on using tickets.