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 a more detailed explanation, you might be interested in reading this post, about the "ready" function.
Also, check out https://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.