How to display an image in Javascript onclick

You can display an image in javascript using onclick event. You have to pass onclick event to button and call the function to display image

Answers 1
  • Display image on click button using javascript arrow function

    <button onClick="showImage()">Button</button>
    <div id="first" style="height:400px; width:400px; display:none;">
        <img src=""/> 
        const showImage = () => {
            document.getElementById("first").style.display ='block';

    This code snippet will help you to display an image on click button using arraw function with onclick event.

  • Back to code snippet queries related javascript