1

I am using a simple script, and when the script is embedded into the actual html page it works just fine, but when it is thrown into an external .js the script no longer works, i am not seeing any errors in the console, it is a jquery delegate function, and i know that the external script is working, because there are other scripts in it that are currently working just fine.

just wondering if there is a cause to this problem, or if anyone else has encountered this.

2
  • You've likely got some error or race condition in there. You'd have to post the script for analysis. Commented May 18, 2011 at 1:21
  • Do you link to the script before you link to the jQuery library file in your HTML? If you do, you'll be accessing things that don't exist. Commented May 18, 2011 at 1:23

1 Answer 1

4

If you're embedding the script in the body of the HTML document, and if your script relies on the existance of elements before the script in the body, then that same script wouldn't work if loaded as an external resource since that code would be executed before the HTML DOM is built.

To make sure your scripts work in either case, wrap any startup code in a $(document).ready(...) method.

Sign up to request clarification or add additional context in comments.

1 Comment

oddly enough, it was the $(document).ready(function() that i was missing. It doesnt work without it. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.