HTML and CSS Reference
In-Depth Information
FiGure 21-1
inTeGraTinG JaVascriPT code
You can incorporate JavaScript code in your web page directly in three different ways. You can set
up your JavaScript so that it activates while the page is loading, after the page has loaded, or interac-
tively when prompted by the user.
activating Javascript instantly
To trigger JavaScript code immediately, add the <script> tag containing the JavaScript code within
the <body> area. For example, if you wanted to show the current date and time, your code might be:
<h1>Today is
<script type=”text/javascript”>
As you can see from Figure 21-2, JavaScript returns a lot of info with just the one line of code. Now
take a look at the example in more digestible parts. First, notice that the <script> tag is within
an <h1> tag; you can intermingle HTML and JavaScript within a <script> tag anywhere in the
<body> area.
Search WWH ::

Custom Search