My requirement is to play audio if someone clicks on page images. The mp3 are directly located on my computer. This is simple, but I can't get any well know code on the internet. This means, I can have a simple link, which will open in a tab if an image is clicked using '<img src=>' with 'ahref'. But what to do, if I have to play an audio or video?
Register and join over 40,000 other developers!
Recent Topics
-
Why is There No Delete Account Option?
deleteMyAccount - Apr 15 2018 07:08 PM
-
Why is There No Delete Account Option?
deleteMyAccount - Apr 15 2018 07:08 PM
-
Salis is an artificial life simulation, based on Tom Ray's Tierra.
nino - Apr 12 2018 09:13 AM
-
What ASP.NET Boilerplate is Not?
dasswadesh - Jan 30 2018 03:16 AM
-
How do you choose best company for android app development?
Amyrivers - Oct 17 2017 01:24 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- import
- syntax
- hardware
- asp.net
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- programming
- javascript
- android
- css
- assembly
- form
- c
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- setup
- sql
- help
- python
- combobox
- binary
- game
- hello world
- grid
- innerHTML

Need a simple example of running audio on clicking the image
Started by MarlenaLegarreta, Nov 07 2016 10:26 PM
javascript click playing audio
1 reply to this topic
#1
Posted 07 November 2016 - 10:26 PM
Recommended for you: Get network issues from WhatsUp Gold. Not end users.
#2
Posted 19 November 2016 - 10:08 AM
Place this is the body of your html file
<audio id="MyAudio"> <source src="/sounds/AudioFileName.mp3" type="audio/mpeg"> </audio>
(Change URL to your audio file as needed)
Then add this Jquery code (inside <script> tags unless you're using a separate file)
$(document).ready(function() { $("img").on('click', function () { $('#MyAudio')[0].play(); }); });
Now every image should play the sound file you specify in the first bit of code.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download