I wrote my html page as follows:
<div>
<img src="Natural1.jpg" id="img1" >
<audio src="sound.mp3" id="audio1" ></audio>
</div>
And my javascript file is like this:
function init(){
audio1 = document.getElementById("audio1");
var img1 = document.getElementById("img1");
img1.addEventListener("click", imgClick, false);
}
function imgClick(){
if(audio1.paused){
audio1.play();
}
else{
audio1.pause();
}
}
document.addEventListener('DomContentLoaded', init, false);
I ran this in chrome12, the script first executed the method document.addEventListener, but it did not get into the init method, why? I tried the method attachEventinstead addEventListenerin IE8, but it still doesn't do it. what is wrong with my code?
source
share