0

How can I change class on a button when it fires active event?

Something like:

$("#invitation button").mouseover(function() {
    $(this).addClass("ui-state-hover");
}).mouseout(function() {
    $(this).removeClass("ui-state-hover");
});

but for the 'active' event.

Jan Krakora
  • 2,500
  • 3
  • 25
  • 52

2 Answers2

1

Much cleaner:

$("#invitation").on('mousedown mouseup', 'button', function(){
    $(this).toggleClass("your-class");
});

See documentation for on() at http://api.jquery.com/on/

Gabe
  • 331
  • 1
  • 3
  • 15
  • Just for clarification, it seems to be impossible to trigger the actual `DOMActive` state described in the spec. See http://stackoverflow.com/questions/8101854/activate-an-elements-active-css-pseudo-class-using-javascript#comment10044626_8102096 – Gabe Apr 30 '13 at 20:46
0
$("#invitation button").mouseover(function() {
    $(this).addClass("ui-state-hover");
});
$("#invitation button").mouseout(function() {
    $(this).removeClass("ui-state-hover");
});

Change class on active(click)

$("#invitation button").mousedown(function() {
    $(this).addClass("your-class");
});
$("#invitation button").mouseup(function() {
    $(this).removeClass("your-class");
});
Memolition
  • 492
  • 1
  • 5
  • 12