jQuery code(s) work when isolated in unique <script> tags
Posted: Sat Dec 24, 2011 10:15 pm
This question is not code specific. It is a very general question, prompted by something I've been observing while building this website, and it really puzzles me.
In the head section of the site I'm working on, I have all the jQuery codes that run the site, enclosed within document ready methods, which are in turn enclosed within <script> tags in the head section of the site. I usually put each code that performs a unique function, within unique script tags. But I began to notice that some of my jQ codes wouldn't work at all when isolated in their own unique document ready method. Then when I transposed this same code to a neighboring document ready method containing another unrealated code which already works, the said code works fine.
So the puzzle is, why wouldn't these codes work when isolated? Are there certain circumstances when this might be the case? Perhaps there is something fundamental about jQuery/javascript that i don't understand that's going on here. Has this been anyones's experience? Answers appreciated.
In the head section of the site I'm working on, I have all the jQuery codes that run the site, enclosed within document ready methods, which are in turn enclosed within <script> tags in the head section of the site. I usually put each code that performs a unique function, within unique script tags. But I began to notice that some of my jQ codes wouldn't work at all when isolated in their own unique document ready method. Then when I transposed this same code to a neighboring document ready method containing another unrealated code which already works, the said code works fine.
So the puzzle is, why wouldn't these codes work when isolated? Are there certain circumstances when this might be the case? Perhaps there is something fundamental about jQuery/javascript that i don't understand that's going on here. Has this been anyones's experience? Answers appreciated.