+ 1
I want to make the audio to play when they tap on image in html 5 so that audio shouldbe back of image
playing audio by taping on image
4 Answers
+ 1
Sure thing!
So a button can do something, or it can do nothing. If you add
<button>Poke</button>
after the </audio> tag and run the code, you can see what a standard button with the browser's default styling looks like.
You technically don't need the button part, as you can simply place the onclick attribute on the img itself (I just updated the code to show the difference) and it would do the exact same thing, but it's a little easier to read the programmer's intention when the img is wrapped in a button, because normally we associate the onclick function with buttons. Other programmers may disagree with my philosophy. You can decide for yourself after you get some experience under your belt. :)
Traditionally, a button is a form element, but can be used outside the <form></form> tags. Semantics enthusiasts will argue over appropriate uses of <button></button> forever.
Maybe that got too detailed, but I hope this helps! :)
+ 2
Hi Charancr,
There's a tiny bit of JavaScript injected into the code, but this seemed the most elegant. Please try:
https://code.sololearn.com/WN43zW6J0CbB
I hope this helps! :)
+ 2
Oh, as a follow-up thought:
Here's a list of event attributes. I tend to think of event attributes as the ones that specifically indicate you should attach JavaScript to them.
https://www.w3schools.com/tags/ref_eventattributes.asp
Here's a brief overview of "onclick" specifically.
https://www.w3schools.com/tags/att_onclick.asp
A brief overview of the syntax here:
https://www.w3schools.com/js/js_intro.asp
:)
+ 1
can you broadly explain the button option as i am still
in the beggining of JavaScript