Can I add javascripts in the middle of my page or it should be btw <head></head>?
Code:. .html codes . <script src=scripts.js language="javascript" type="text/javascript"></script> . .html codes . .
| SitePoint Sponsor |


Can I add javascripts in the middle of my page or it should be btw <head></head>?
Code:. .html codes . <script src=scripts.js language="javascript" type="text/javascript"></script> . .html codes . .

To be as unobtrusive as possible:
<script type="text/javascript" src="external.js"></script>
</head><body>
And then put all the necessary javascript code into its own separate external.js file.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">





You can, but you shouldn't. The idea is to keep the javascript(called the behavior) separate from the html(called the structure), and to keep the css(called the presentation) separate as well. It makes maintenance(i.e. the ability to change things) easier.Can I add javascripts in the middle of my page
The best practice is to link to a javascript file using script tags in the <head> by using a src attribute in the script tags. The next best practice is to put the javascript directly in the <head>.
Last edited by 7stud; Feb 22, 2007 at 05:04.




You can put them (with src=) anywhere you like. But lose the 'language=' attribute-
the only browsers that use 'language' will download javascript files without it.
They only pay attenton if a version number is specified.
Last edited by mrhoo; Feb 22, 2007 at 01:12.
Bookmarks