Matt
Matt

Reputation: 2327

How do I target the :active pseudo-class in jQuery?

I am looking to target the :active psuedo class in jQuery. Essentially when the active state is activated, I would like a simple animation to occur. Is there a way to target ":active" just as there is in CSS?

Upvotes: 1

Views: 313

Answers (2)

Hussein Nazzal
Hussein Nazzal

Reputation: 2557

for inputs i think this will be what you want

$(":input").focusin(function() { .... });
$(":input").focusout(function() { .... })

Upvotes: 0

Explosion Pills
Explosion Pills

Reputation: 191819

There is no way to do this in JavaScript, but you can bind the animation to events that would cause an element to be considered :active, i.e. click:

$(element).on('click', function () { /* anmiation * / });

Animations are also possible via CSS and you would be able to use :active directly with those.

Upvotes: 3

Related Questions