It is very simple in fact. If your script is not bound to a document ready event, it will fire up instantly, that is, when the page is being loaded, NOT when it has loaded. What it means is that the HTML controls/tags below your script tag have not been added yet to the DOM. And as such, attempting to interact with them will not work.
If you place your script tags after the control/tag is created, the tag is in the DOM and jquery "sees" it.
For these reasons it is always recommended to bind your javascript to a document "ready" function, so that it will fire only when the DOM tree has been properly and completely instantiated.
For a more detailed explanation, you might be interested in reading this post, about the "ready" function.
Also, check out http://stackoverflow.com/q/1307929/866172 if you are interested in knowing how the web page is loaded by the browser (hint: top to bottom, or "as it is seen"). The advice in the top answer is to place the script tag at the end of the document, which makes sense, but if you are using jquery, whatever the place of your script tag is, if you wrap your code in a "ready" function you won't have any problems.