I am trying to create a clickable button that includes a span with a .png image inside. Currently, the button only responds when I click around the image, not directly on it. I have searched for solutions but haven't found one that addresses my specific issue.
HTML
<button id="btn3"><span class"btn3"></span></button>
CSS
span.btn3 {
background: url("./images/raincloud.png") no-repeat top left;
background-size: contain;
cursor: pointer;
display: inline-block;
height: 80px;
width: 80px;
}
Edit:
Below is the JavaScript function responsible for changing the audio/video file when a specific button is clicked.
[].forEach.call(document.getElementsByClassName('btn'),
function(btn) {
btn.addEventListener('click', function(e) {
switch (e.target.id) {
case "btn3":
video.src = "./video/rain2.mp4";
video.play();
break;
case "btn4":
video.src = "./video/rain1.mp4";
video.play();
break;
case "btn5":
audio.src = "./audio/rain.mp4";
audio.play();
break;
case "btn6":
audio.src = "./audio/rain2.mp4";
audio.play();
break;
}
})
})