Possible Duplicate:
$ not defined using jQuery in Wordpress

I need to trigger a alert box when video ends

THis is the code i got from google

$("iframe[src^='http://www.youtube.com']").bind("ended", function() {
alert("I'm done!");

I am just using the oembed function of wordpress to play youtube videos

I dont now why there are not working

  • Voted to close as off topic, this is a Youtube player issue, not a WordPress issue. The embed itself is defined by Youtube, as is the API, as is the JS, as is the player controls. This is a Javascript question should belongs on the main Stack Overflow site
    – Tom J Nowell
    Commented Jan 28, 2013 at 10:56
  • i added here becuase the script works in normall php sites but doesnt works in wordpress as wordpress is using o-embed function to embed videos
    – vaibhav
    Commented Jan 28, 2013 at 11:15
  • So it is not a WordPress issue it's an OEmbed issue? Then it's still offtopic
    – Tom J Nowell
    Commented Jan 28, 2013 at 11:54

1 Answer 1


You can track the state of the youtube video, do you have the link to the youtube video? Use this youtube API function to get the result, and if it hits you back with a "0" you can initiate the alert(); function


Returns the state of the player. Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5).

Not the answer you're looking for? Browse other questions tagged or ask your own question.