johnny johnny - 5 months ago 59
Javascript Question

Does javascript have to be in the head tags?

I believe javascript can be anywhere (almost), but I almost always see it in between

. I am using jquery and wanted to know if it has to be in the head tags for some reason or if will break something if I move it. Thank you.

EDIT: Why is it almost always in the head tags?


JavaScript is executed wherever it is found in the document. If you place inline JavaScript in the body, it will be executed when the browser comes to it. If you're using $(document).ready(...) to execute things, then the positioning shouldn't matter. Otherwise, you may find corner cases where it matters. In general, it does not matter. Scripts end up in the head tag mostly out of tradition.