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.

4
  • what do you mean by active? seems to be same as click event
    – Sachin
    Apr 30, 2013 at 20:34
  • There is no active event. Do you mean focus?
    – Jacob
    Apr 30, 2013 at 20:34
  • Do you mean CSS pseudo class :active ?
    – A. Wolff
    Apr 30, 2013 at 20:35
  • @roasted Yes, I mean the same event that is applied when is used this pseudo class. Apr 30, 2013 at 20:38

2 Answers 2

1

Much cleaner:

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

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

1
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");
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.