Youtube Javascript API code outside jQuery ready function: http://jsbin.com/umituf/1
Inside jQuery ready function: http://jsbin.com/umituf/2
I would like to use jQuery because when the video is stopped (even === 0
) and loadmore()
method is called, I want to write a ajax call in jQuery to go back to the server and fetch more video id's so they can be further passed to the cuePlaylist(...)
method.
Why am I not able to mix jQuery and the API and How can it be done?
on( "ready", handler ) , deprecated as of jQuery 1.8 and removed in jQuery 3.0.
jQuery ready() Method The ready event occurs when the DOM (document object model) has been loaded. Because this event occurs after the document is ready, it is a good place to have all other jQuery events and functions. Like in the example above. The ready() method specifies what happens when a ready event occurs.
A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.
The key difference between $(document). ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc.
The functions need to be defined in the global scope.
http://jsbin.com/umituf/3
Edit for clarification:
The youtube api script looks for those particular functions on the global scope. The api script does not have access to the scope that is created within the document.ready callback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With