-2

Would anyone be able to help me here as I'm not quite sure what the problem is, I think it has something to do with placement of one of the lines.

https://jsfiddle.net/70kwwpqp/

<div class="animatedButton">

    <audio id="Sound" src="Sounds/beep.mp3"> </audio>

    <a href="Home.html">
    <button class="aButton" <onclick="playBeep()"> <img src="img/Home.png"> </button>
    </a>

  </div>

function playBeep ()
{

var sound = document.getElementById("aButton")
sound.play()

}

2 Answers2

1

  <audio id="audio" src="http://www.soundjay.com/button/beep-07.wav" autostart="false" ></audio>
    <a onclick="playSound();"> Play</a>
    <script>
    function playSound() {
          var sound = document.getElementById("audio");
          sound.play();
      }
    </script>
Nihal
  • 5,262
  • 7
  • 23
  • 41
0

You have a syntax error and the JSFiddle highlights it for you. There should not be a < before onclick.

Also, you are getting the button and asking it to play(). You should be getting the audio element by id Sound and playing that.

mintychai
  • 281
  • 3
  • 10