Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8319523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:21:13+00:00 2026-06-08T22:21:13+00:00

This is my code for playing a html5 audio (which doesn’t work) $(‘img.play_media’).bind(‘click’,function(){ src=$(this).attr(id);

  • 0

This is my code for playing a html5 audio (which doesn’t work)

$('img.play_media').bind('click',function(){
src=$(this).attr("id");                     $('audio[id=resource_audio]').children('source').attr("src","testuser/resources/"+src);
var audio= document.getElementById('resource_audio');
audio.play();
return false;
});

<audio id="resource_audio" >
<source src="" type="audio/mp3" />
</audio>

As you can see, I am trying to get the src on img click ,which is set to the image id and in opera I can see the play starting. But, the audio doesn’t play. Any help is appreciated.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:21:15+00:00Added an answer on June 8, 2026 at 10:21 pm

    Please provide the HTML for the img. I’ve cleaned up your code a bit, but probably won’t help with your problem:

    $('img.play_media').click(function(event){
      $("#resource_audio")
        .attr("src","testuser/resources/"+this.id)
        .get(0).play();
    });
    
    <audio id="resource_audio">
      Your browser does not support the <code>audio</code> element.
    </audio>
    
    • Note: make sure of two things: a) the audio file is actually at the correct location, b) the web server is configured to serve (respond) with the correct MIME-type.

    You may also want to look at https://developer.mozilla.org/en/HTML/Element/audio.

    <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    </head>
    <body>
        <h1>Heading</h1>
        <div id="doc">
            <img class="play_media" id="test.mp3" src="status-on.png" style="width:15px;margin-right:0%;" > 
            <audio id="resource_audio">
              Your browser does not support the <code>audio</code> element.
            </audio>
        </div>
        <script>
        $('img.play_media').click(function(event){
          $("#resource_audio")
            .attr("src",this.id)
            .get(0).play();
        });
        </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code disabled mouse scroll functionality, when i click on the document. $(document).on(click, function
i'm playing with MEF and in the example i see this code ( i
I was playing around with some Javascript snippets today and noticed that this code
I am playing youtube video on iPad via webView using this code. NSString *htmlString
I am playing an embeded youtube video with the play() function. This is all
This a small portion of the javascript code I used for an HTML5 music
i am using this code for playing music for my website way2enjoy.com .it playes
this code gives an instant seg fault,I tried placing printf's all over, I even
Im planing on using this code to make random sounds play with an action,
When placing a conditional breakpoint in my code, this fails: Sophie Dee <> myString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.