Languages
[Edit]
EN

JavaScript - change image on click

3 points
Created by:
Leen-Kerr
571

In this article, we would like to show you how to change the image src on click event using JavaScript.

Quick solution:

or:

 

Practical examples

Edit

1. by clicking on image

Edit

In this section, we present practical example that changes image src when you click the image.

2. by clicking on button

Edit

In this section, we present practical example that changes image src when you click the button.

Note: check this article to know more about methods of how to add an onclick event to the HTML element.

 

References

Edit
  1. HTMLImageElement.src - Web APIs | MDN
  2. <img>: The Image Embed element - HTML: HyperText Markup Language | MDN

Alternative titles

  1. JavaScript - change image src onclick()
  2. JavaScript - change image url on click event
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join