0

enter image description here

I'm trying to call fxn function outside $(document).ready(), but I can't get it working. It returns ReferenceError: fxn is not defined.. anything I missed?

1
  • 1
    you should call in document.ready()... otherwise function call line will be executed before function definition or every thing outside of document.ready(). Commented Apr 29, 2015 at 3:02

1 Answer 1

1

Because of the way jQuery works. This error is predictable.

What is happening, is the declaration of fxn is waiting until the document is actually ready. Where the call to this method is not. So, by attempting this you are in essence trying to call a function that doesn't yet exist.

As per: http://learn.jquery.com/using-jquery-core/document-ready/

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. Code included inside $( window ).load(function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.

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

Comments

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.