Adding JavaScript to an HTML Document

<head>   <script type="text/javascript">     alert("JavaScript is Enabled!");   </script> </head>

You can add JavaScript to an HTML document using HTML <script> tags. When the browser encounters a <script> tag, it parses the contents and then executes the JavaScript inside. Typically, the <script> tags are added to the <head> element, but you can also add them to the <body> element.

The web browsers currently default all scripts to javascript; however, it is a good idea to still set the type to "text/javascript" for future compatibility if that changes.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.