0

I want to show a image in Html when click in a button with Javascript function. How can i do this?

I already search for this in internet, but i can't resolve this problem.

In Html:

<button onclick="myFunc()">Anything</button>

I don't know what I can do for show a image in Html when click in button with Javascript Function

Samtapes
  • 194
  • 1
  • 3
  • 8
  • Please edit your question to make it clear what you're asking. What does your setup look like; is there already an image on the page that is invisible, or do you need to add a new image to the page? That kind of info is missing. Tallboy's answer may help, or it may not; he makes a lot of assumptions about your situation. – Mr Lister May 07 '19 at 06:33

1 Answers1

1

function myFunc() {
  var element = document.getElementById('something');
  element.style.display = 'block';
}
<img id="something" src="https://www.gravatar.com/avatar/344337b6819f2f513fa80bb227be3c2d?s=48&d=identicon&r=PG" style="display: none">
<button onclick="myFunc()">Anything</button>
<img id="something" src="file.png">
<button onclick="myFunc()">Anything</button>

<script>
  function myFunc() {
    var element = document.getElementById('something');
    element.style.display = 'block';
  }
</script>
Tallboy
  • 12,847
  • 13
  • 82
  • 173