HTML and CSS Reference
In-Depth Information
without changing them. In this example, car is an object, and its properties are hood,
trunk, color, year, and manufacturer. Hood and trunk could be considered properties as
well. Open and close are methods of hood and are also methods of trunk.
With respect to the DOM, we can write to the document using the write() method of
the document object. The structure is as follows:
document.write("text to be written to the document");
We can use this in JavaScript to write text and XHTML tags to a document and the
browser will render it.
The alert() method used in the next Hands-On Practice is a method of the window
object. It can be written as follows:
window.alert("message");
The window object is assumed to exist and can be omitted. If the window doesn't exist,
the script doesn't exist either.
One property of the document is lastModified . This property contains the date
on which the file was most recently saved or modified, and we can access it using
document.lastModified . This is a read-only property that we can write to the
document or use for some other purpose.
HANDS-ON PRACTICE 14.2
In this Hands-On Practice you will practice using the write() method of the document,
and the lastModified property of the document. You will use document.write() to add
text and some XHTML tags to an XHTML document. You will also use document.write()
to write the date the file was last saved to the document.
Open the alert.html document and edit the script block as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>JavaScript Practice</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>Using JavaScript</h1>
<script type="text/javascript">
<!-- <![CDATA[
document.write("<p>Using document.write to add text</p>");
document.write("<h2>Notice that we can add XHTML tags too!</h2>");
// ]]> -->
</script>
<h3>This document was last modified on:
<script type="text/javascript">
Search WWH ::




Custom Search