O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required