views:

92

answers:

1

QUESTION: How do I trigger the :active state for non-anchor elements via JavaScript (jQuery)?


While reviewing Section 5.11.3 of the W3C CSS2 specification in reference to :hover pseudo selector to see about triggering the activation of a , I came across the following which led me to believe it should be possible:

"The :active pseudo-class applies while an element is being activated by the user. For example, between the times the user presses the mouse button and releases it."

"CSS does not define which elements may be in the above states, or how the states are entered and left. Scripting may change whether elements react to user events or not, and different devices and UAs may have different ways of pointing to, or activating elements."

Thanks for the assist!

A: 

You can't trigger a css pseudo selector like :active with javascript. There is no function / handler which could be executed, so even if you trigger a click on an element which has a css :active pseudo selector set (setting the background color to red for instance), nothing is going to happen.

jAndy
That is disappointing if true. I know I haven't found a way to do it, but I don't see why there shouldn't be. =(
Andrew F