search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

1 answers
Q&A CSS only method to dynamically modify image src on click without using JavaScript

0

I need to change the src of an image on mouse click using only css like

img:active {
}
Your Answer
submit

1 answers
0

You can achieve this by using a element replacing the function content attribute.

Please note that you cannot set up any ARIA or other accessibility-related features using this technology, so the information you convey may be lost to parts of the user base. (This may be illegal depending on what the information is, who you are, and the control you are in/marketed to).

You may want to set tabindex or wrap the image in a button to make it accessible via keyboard/etc.

Also note that :active means "on click" not "after click". CSS has no "after click" pseudo-class (although :focus is sufficient in some cases).

img:active {
    content: url(http://placekitten.com/200/200);
}
<img src="http://placekitten.com/g/200/200" alt="">
2024-04-07 10:34:46

submit

Popular tool

vc9-vc14 (32+64 bit) runtime library collection (link below)

vc9-vc14 (32+64 bit) runtime library collection (link below)

Download the collection of runtime libraries required for phpStudy installation

VC9 32-bit

VC9 32-bit

VC9 32-bit phpstudy integrated installation environment runtime library

PHP programmer toolbox full version

PHP programmer toolbox full version

Programmer Toolbox v1.0 PHP Integrated Environment

VC11 32-bit

VC11 32-bit

VC11 32-bit phpstudy integrated installation environment runtime library

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use