Usually I would use :hover, but I want my website to be accessible on touchscreen media too.
I know I can use :active, but as soon as I let go of the mouse button, it goes back to its inactive state.
Effectively I want:
Mouse Down : Div goes green
Mouse Up: Div stays green
Mouse Down: Div goes red
Mouse Up: Div stays red
Instead of:
Mouse Down: Div goes green
Mouse Up: Div goes red
The onmousedown event occurs when a user presses a mouse button over an element. Tip: The order of events related to the onmousedown event (for the left/middle mouse button): onmousedown.
The mousedown event is fired at an Element when a pointing device button is pressed while the pointer is inside the element.
A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :hover selector to style links when you mouse over them.
The mouseup event is fired at an Element when a button on a pointing device (such as a mouse or trackpad) is released while the pointer is located inside it. mouseup events are the counterpoint to mousedown events.
Without relying on jQuery:
The :active
pseudo-class is used to apply css to elements while they're being clicked upon.
.button { color: red; } .button:active { color: green; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With