1

I'm trying to trigger a method with jQuery's click Event. I want to use the Object.method directly, but it only works when I wrap it in a function. Why?

Example Working Code:

function play () { a.play(); }
a = new Audio("http://music-ringtone.com/ringtones/04/music-ringtone-com-Live%20to%20Win_68_04.mp3");
$("#my-button").click(play);

Example Non-Working Code:

a = new Audio("http://music-ringtone.com/ringtones/04/music-ringtone-com-Live%20to%20Win_68_04.mp3");
$("#my-button").click(a.play);
Sepero
  • 4,489
  • 1
  • 28
  • 23

0 Answers0