1

I'm trying to play a sound in html.

I putted audio tag in html and define a function to play it

but when I use the .play() function of js, the jquery return an error.

audio.play() is not a function.

when I remove jquery file, the sound is working.

how can I clear that the function is not jquery's?

function playblop()
    {
        var ab = document.getElementById('blop').play();
    }
Pooya
  • 1,508
  • 3
  • 17
  • 38

2 Answers2

1

put audio tag on autoplay...

every time you need to play, append the tag...

$("body").append("<audio autoplay>...</audio>");
mehran
  • 62
  • 1
  • 1
  • 9
-1

use a static object as namespace e.g.

    var myobject = {
        playblop: function(){

        }
    };
    //call the function
    myobject.playblop();

Updated: Ignore the code about and read this: HTML5 Audio and jQuery

Community
  • 1
  • 1
matpol
  • 3,042
  • 1
  • 15
  • 18