Problem with Javascript and YouTube API. Help is much appreciated!
What is happening is
1. site loads
2. it runs your script
3. your script sets ready callback to bind click event on all .thumbnail
4. your script runs AJAX
5. page finishes loading -> ready callback kicks in and sets click for all .thumbnail (there are no thumbnail yet)
6. AJAX finishes and callback is creating .thumbnails
Even if ajax would end before ready callback there is possibility that there won't be #thumbContainer yet.
What I would do is move all from ready callback to the end of getJSON callback and move whole script to the bottom of body (under #thumbContainer) then you will be sure all will run when all required DOM elements exists.
P.S.: Firefox's debugger has ability to show events attached to DOM element. You would see that your working version have event attached to it and the version that doesn't work does not have any events. That would direct you that something is wrong with ready callback that is setting the event.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now