title: Javascript -add onlick within a function
body: <p>I have encountered a slight difficulty within my code. Following function is involved in a part of a small game for private use. My question is, how can add a sound if the image generated is clicked on?</p>
  
  <p>Code: </p>
  
  <pre><code>function img1() {
      var img = document.createElement('img');
      img.src = "img1.png";
      document.body.appendChild(img);
      img.className = "img1";
  }
  </code></pre>
  
  <p>I'd like this soundfunction to be triggered on click:</p>
  
  <pre><code>function sound1() {
      var audio = new Audio('s1.wav');
      audio.play();
  }
  </code></pre>