Alan Alan - 2 months ago 4x
CSS Question

How to make a change in the dom that lasts for one click

I am building a webpage and i have set a body

. Is there a way to change the url of the image when the user presses the mouse key, and change it back when the mouse key is released? Basically the change lasts the same amount of time as the click itself.

Also, how do i make sure this change works for a click anywhere on the page? Will adding an event listener to the body element suffice? Thanks in advance.


Pure CSS:

body:active {
    background-image: [IMAGE];

Example jsfiddle