HTML and CSS Reference
In-Depth Information
There are several other features of objects, as well as a few different
ways to create them, but you won't need to know them for this topic.
Just bear in mind that whenever you see periods, you're almost always
looking at objects with properties and methods.
You now know enough to start putting JavaScript to the use
it was intended for—manipulating web pages. But to do that,
you need to understand how to link JavaScript to a web page.
How JavaScript fits into HTML
The point of learning JavaScript is using it in browsers to do things
with web pages. In this section, you'll learn how to get your JavaScript
into HTML . You can do this three primary ways: inline in a <script>
element, linked in a separate file, and inline in an event handler. Let's
look at each in turn.
Inline <script> element
The most straightforward way to add JavaScript to your web page is
to include it inside a <script> element. Here's a simple example:
<!DOCTYPE html>
<html>
<head>
<title>Inline script</title>
</head>
<body>
<script>
window.alert("Inline script!");
</script>
</body>
</html>
If you create a web page using this code and load it in your browser,
you should see something like the following screenshot (if you're using
IE , you may need to click the warning bar to allow JavaScript in a
local file).
Search WWH ::




Custom Search