I have this jsfiddle.
When I move the script from the upper panel to the lower panel, it does not work any more.
And why can’t I use jQuery to target the buttons? Now, I have to use vanilla JavaScript, because jQuery does not work.
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
In JSFiddle, at the left panel screenshot, you can choose where to place the script. By default, it’s wrapped in an
onloadevent within the head. By default, the Mootools library is loaded.The reason that the YouTube Player API does not work with the default settings is that the API expects a global
onYouTubePlayerAPIReadyevent to be defined. When the code is wrapped in anonloadevent, the function isn’t global any more.The solution is to properly use JSFiddle: Use
no wrap (body)andjQuery 1.7.2: http://jsfiddle.net/4WPmY/12/.Another solution, though less nice than the recommended one, is to globally define
onYouTubePlayerAPIReadyby setting it as a property ofwindow: http://jsfiddle.net/4WPmY/13/