0

HTML:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>

<body>
<div class="buttons" >
<li><pre><strong><a href="home.html">Home</a></strong> </pre></li>
</div>
</body>

CSS:

.buttons{
 font-size:16px;

position:fixed;
bottom:217px;
left:183px;
}

Here is my code without any sound, how can I enter a sound on it?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Duplicate of http://stackoverflow.com/questions/8489710/play-an-audio-file-using-jquery-when-a-button-is-clicked , or arguably "too broad" – zwol Mar 14 '15 at 00:00

1 Answers1

1

you can use this jQuery code:

  $(document).ready(function() {
        var audioElement = document.createElement('audio');
        audioElement.setAttribute('src', 'audio.mp3');
        audioElement.setAttribute('autoplay', 'autoplay');
        //audioElement.load()

        $.get();

        audioElement.addEventListener("load", function() {
            audioElement.play();
        }, true);

        $('.play').click(function() {
            audioElement.play();
        });

        $('.pause').click(function() {
            audioElement.pause();
        });
    });

And HTML for controllers:

<div class="play">Play</div>

<div class="pause">Stop</div>

And next time please use search:

Play an audio file using jQuery when a button is clicked

Community
  • 1
  • 1