Talk:JavaScript/JavaScript within HTML

Where should the tags go? What are the implications/differences between having it in vs. ?

You can define functions, global variables, etc. in the head. You would use it in the body if you would want, for example, to use document.write to insert a custom blurb in the body of the page. If you used document.write in the head, it would replace the whole body with the string passed to it.

It may also be worth noting that officially Javascript is supposed to be used with application/x-javascript as opposed to text/javascript, however this is unsupported in some browsers. Not surprisingly, IE is one of those browsers.

--70.89.239.70 22:15, 13 November 2007 (UTC)


 * See JavaScript and HTML Script Tags for a persuasive opinion piece regarding this issue. Also, here are some relevant standards:
 * Scripts in HTML Documents
 * XHTML Scripting Module
 * Script and Style elements, XHTML™ 1.0
 * --Jesdisciple (talk) 23:32, 1 November 2008 (UTC)


 * Information about where script tags can go has been updated now, including information from Yahoo's best practices for speeding up your web site regarding putting scripts at the bottom of the page.


 * An update regarding the conflict over text/javascript and application/javascript has been included too.
 * --Pmw57 (talk) 13:06, 20 February 2009 (UTC)

I had to look up the term meta tag. How should definitions of terms be added to the page?
 * --Mtmomx2 (discuss • contribs) 14:03, 24 August 2012 (UTC)

Both of one CDATA
The text refers to "... both CDATA tags" being commented out, but there is only one in the code snippet above that. I am just now learning JavaScript myself, so I can't be sure if the error is in the code snipped or the explanatory text. 18:07, 22 February 2016 (UTC)
 * I have clarified the text. Ftiercel (discuss • contribs) 12:41, 14 March 2016 (UTC)