Share Posted June 2, 2015 Hi guys, today morning i was reading the "get started page" on the GSAP web site, i was finding it really interesting, then i decided to try it. But as soon as i wrote my code and launched on google chrome, it didn't seem to work at all. Then i started wondering if there were some problems with my browser even because i tried the same code on CODEPEN () and it's working perfectly. So my question is, what to i have to do, to run the code on my browser? ps. I'm new here, this is my first post and i really hope this is the right section, these are the right topic tags, if not i'm really sorry about it. See the Pen EjWNRg by RyanLeenox (@RyanLeenox) on CodePen Link to comment Share on other sites More sharing options...
Share Posted June 2, 2015 Hi Ryan Leenox try this : document.addEventListener('DOMContentLoaded', function() { //your script here }); or with jquery : $( document ).ready(function() { //your script here }); 4 Link to comment Share on other sites More sharing options...
Share Posted June 3, 2015 The reason your code works on CodePen is because the JavaScript is placed right before the closing </body> tag, so the #tester element has already been created by the time your code executes. When you place your JavaScript in the <head> like that, the element doesn't exist yet, so your code isn't able to find #tester. If you're going to keep your JavaScript in the <head>, you're going to have to use one of the solutions Diaco shared. Location matters... See the Pen xGqgqY?editors=100 by osublake (@osublake) on CodePen 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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