samedi 28 février 2015

How do i make music play when image is clicked?


I have a image that changes the background of the page already but i would also like it to play music when i click the image. Can anyone help? Here's My code


HTML:



<div id="background">
<div id="box">
<div class="button">
<img src="alien.png" type="button" id="my-button">
<br>
<p>Click The Alien!</p>
</div>
</div>


JavaScript:



<script>
var myData = {

1: {
imageUrl: "8.gif",

},

};

function changeImage() {
var randomNumber = Math.floor((Math.random() * 1) + 1);
document.getElementById("background").style.background = "url('" + myData[randomNumber].imageUrl + "')";
document.getElementById("text-box").innerHTML = myData[randomNumber].text;
}
document.getElementById("my-button").addEventListener("click", changeImage);




Aucun commentaire:

Enregistrer un commentaire