Why is the onclick null in line 13 when the id is clear?
<script>
var mySong = document.getElementById("mySong");
var icon = document.getElementById("icon");
icon.onclick = function(){
mySong.play();
</script>
<html>
<body>
<img src = "favpng_button.png" id="icon">
this id "icon" <shoul correspond with js>
<audio id = "mySong">
<source src="media.mp3" type="audio/mp3">
</audio>
</body>
</html>
I did the same as the person in this video https://www.youtube.com/watch?v=w5fCIhI0FyE&t=486s 9:03
The audio file is in the same
folder as the html and javascript and
it is called media.mp3
.
I think that
the error has something to do with a
typing error. Maybe there is a simpler
way of creating a html page which automatically
plays music because this is the goal.