Jasper Jasper - 6 months ago 14
HTML Question

No mouseup after losing hover

http://jsfiddle.net/rpfHw/

We have an

input
and class
active
, which is added on
mousedown
and removed on
mouseup
.

It works good when mouse cursor is placed over input.

The problem is,
mouseup
doesn't work after you click on
input
, hold and remove cursor from it - class
active
is not removed.

Can it be fixed?

Answer

That's because mouseup was not fired on the input, but outside it. You can use a generic event handler on the document object for that:

$(document).mouseup(function() {
    $('input.active').removeClass('active');
});

http://jsfiddle.net/rpfHw/1/