Sams Teach Yourself HTML, CSS and Javascript 2nd Ed Plus Jquery PDF
Sams Teach Yourself HTML, CSS and Javascript 2nd Ed Plus Jquery PDF
Meloni
SamsTeach Yourself
HTML, CSS
and JavaScript
All
One
in
SECOND EDITION
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities
(which may include electronic versions; custom cover designs; and content particular to
your business, training goals, marketing focus, or branding interests), please contact our
corporate sales department at [email protected] or (800) 382-3419.
CHAPTER 3: Understanding Cascading Style CHAPTER 15: Working with the Document Object
Sheets Model (DOM)
CHAPTER 20: Using Windows 489 CHAPTER 24: First Steps Toward Creating
Rich Interactions with
Controlling Windows with Objects . . . . . . . . . . . . . . . 489
jQuery UI 557
Moving and Resizing Windows . . . . . . . . . . . . . . . . . . . 493
Preparing to Use jQuery UI . . . . . . . . . . . . . . . . . . . . . . . . 557
Using Timeouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Using Selectors in jQuery UI . . . . . . . . . . . . . . . . . . . . . . 558
Displaying Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Positioning UI Elements with
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499 jQuery UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559
Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500 Applying jQuery UI Effects . . . . . . . . . . . . . . . . . . . . . . . . . 564
Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500 Using jQuery UI Widgets for Advanced
Interactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585 CHAPTER 27: Organizing and Managing
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586 a Website 641
Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586 When One Page Is Enough . . . . . . . . . . . . . . . . . . . . . . . . 642
Reader Services
Visit our website and register this book at informit.com/register for convenient access to any
updates, downloads, or errata that might be available for this book.
This page intentionally left blank
CHAPTER 4
Understanding JavaScript
The World Wide Web (WWW) began as a text-only medium—the first WHAT YOU’LL LEARN IN
browsers didn’t even support images within web pages. The Web has THIS CHAPTER:
come a long way since those early days. Today’s websites include a ▶ What web scripting is and
wealth of visual and interactive features in addition to useful content: what it’s good for
graphics, sounds, animation, and video. Web scripting languages, ▶ How scripting and
such as JavaScript, are one of the easiest ways to spice up a web page programming are different
(and similar)
and to interact with users in new ways.
▶ What JavaScript is and
The first part of this chapter introduces the concept of web scripting where it came from
and the JavaScript language. As the chapter moves ahead, you’ll ▶ How to include JavaScript
learn how to include JavaScript commands directly in your HTML commands in a web page
documents, and how your scripts will be executed when the page is ▶ What JavaScript can do for
viewed in a browser. You will work with a simple script, edit it, and your web pages
test it in your browser, all the while learning the basic tasks involved ▶ Beginning and ending
scripts
in creating and using JavaScript scripts.
▶ Formatting JavaScript
statements
▶ How a script can display a
Learning Web Scripting Basics result
You already know how to use one type of computer language: ▶ Including a script within a
HTML. You use HTML tags to describe how you want your document web document
formatted, and the browser obeys your commands and shows the ▶ Testing a script in your
formatted document to the user. But because HTML is a simple text browser
markup language, it can’t respond to the user, make decisions, or ▶ Modifying a script
automate repetitive tasks. Interactive tasks such as these require a ▶ Dealing with errors in
scripts
more sophisticated language: a programming language or a scripting
language. ▶ Moving scripts into
separate files
Although many programming languages are complex, scripting
languages are generally simple. They have a simple syntax, can
78 CHAPTER 4: Understanding JavaScript
NOTE perform tasks with a minimum of commands, and are easy to learn.
Interpreted languages have JavaScript is a web scripting language that enables you to combine
their disadvantages—they scripting with HTML to create interactive web pages.
can’t execute really quickly,
so they’re not ideally suited
for complicated work, such as Scripts and Programs
graphics. Also, they require the
interpreter (in JavaScript’s case, A movie or a play follows a script—a list of actions (or lines) for the
usually a browser) in order to actors to perform. A web script provides the same type of instructions
work. for the web browser. A script in JavaScript can range from a single line
to a full-scale application. (In either case, JavaScript scripts usually run
within a browser.)
You can do all this and more with JavaScript, including creating entire
applications. We’ll explore the uses of JavaScript throughout this book.
<html lang="en">
<head>
<title>The American Eggplant Society</title>
</head>
<body>
<h1>The American Eggplant Society</h1>
<p>Welcome to our site. Unfortunately, it is still
under construction.</p>
<p>We last worked on it on this date:
<script type="text/javascript">
<!-- Hide the script from old browsers
document.write(document.lastModified);
// Stop hiding the script -->
</script>
</p>
</body>
</html>
80 CHAPTER 4: Understanding JavaScript
FIGURE 4.1
Using document.write to display
a last-modified date.
In this example, we placed the script within the body of the HTML
document. There are actually four places where you might use scripts:
▶ In the body of the page—In this case, the script’s output is
displayed as part of the HTML document when the browser loads
the page.
▶ In the header of the page between the <head> tags—Scripts
in the header should not be used to create output within the
<head> section of an HTML document, since that would likely
result in poorly-formed and invalid HTML documents, but these
scripts can be referred to by other scripts here and elsewhere. The
<head> section is often used for functions—groups of JavaScript
statements that can be used as a single unit. You will learn more
about functions in Chapter 14, “Getting Started with JavaScript
Programming.”
How JavaScript Fits into a Web Page 81
TIP
Using Separate JavaScript Files External JavaScript files have
When you create more complicated scripts, you’ll quickly find that a distinct advantage: You can
your HTML documents become large and confusing. To avoid this link to the same .js file from
two or more HTML documents.
problem, you can use one or more external JavaScript files. These are
Because the browser stores this
files with the .js extension that contain JavaScript statements. file in its cache, this can reduce
the time it takes your web
External scripts are supported by all modern browsers. To use an
pages to display.
external script, you specify its filename in the <script> tag:
<script type="text/javascript" src="filename.js"></script>
You can create the .js file using a text editor. It should contain one
or more JavaScript commands, and only JavaScript—don’t include
<script> tags, other HTML tags, or HTML comments. Save the .js file
in the same directory as the HTML documents that refer to it.
<html lang="en">
<head>
<title>Event Test</title>
</head>
<body>
<h1>Event Test</h1>
<button type="button"
onclick="alert('You clicked the button.')">
Click Me!</button>
</body>
</html>
Improving Navigation
Some of the most common uses of JavaScript are in navigation systems
for websites. You can use JavaScript to create a navigation tool—for
example, a drop-down menu to select the next page to read, or a
submenu that pops up when you hover over a navigation link.
When it’s done right, this kind of JavaScript interactivity can make a
site easier to use, while still remaining usable for browsers that don’t
support JavaScript (or HTML5/CSS3, which can also be used to create
great navigation).
Validating Forms
Form validation is another common use of JavaScript, although the
form validation features of HTML5 have stolen a lot of JavaScript’s
Exploring JavaScript’s Capabilities 83
thunder here as well. A simple script can read values the user types
into a form and make sure they’re in the right format, such as with ZIP
Codes, phone numbers, and e-mail addresses. This type of client-side
validation enables users to fix common errors without waiting for a
response from the web server telling them that their form submission
was invalid. You’ll learn how to work with form data in Chapter 26,
“Working with Web-Based Forms.”
Special Effects
One of the earliest and most annoying uses of JavaScript was to create
attention-getting special effects—for example, scrolling a message in
the browser’s status line or flashing the background color of a page.
NOTE
Displaying Time with JavaScript
UTC stands for Universal Time
(Coordinated), and is the atomic One common use of JavaScript is to display dates and times in the
time standard based on the old browser, and that’s where we’ll start putting some scripting pieces
GMT (Greenwich Mean Time) together. Because JavaScript runs on the browser, the times it displays
standard. This is the time at
the prime meridian, which runs
will be in the user’s current time zone. However, you can also use
through Greenwich, London, JavaScript to calculate “universal” (UTC) time.
England.
Your script, like most JavaScript programs, begins with the HTML
<script> tag. As you learned earlier in this chapter, you use the
CAUTION <script> and </script> tags to enclose a script within the HTML
Remember to include only document.
valid JavaScript statements
between the starting and To begin creating the script, open your favorite text editor and type the
ending <script> tags. If the beginning and ending <script> tags as shown:
browser finds anything but valid <script type="text/javascript"></script>
JavaScript statements within the
<script> tags, it will display a
JavaScript error message. In this script, you’ll use JavaScript to determine the local and UTC
times and then display them in the browser. Fortunately, all the hard
parts, such as converting between date formats, are built in to the
JavaScript interpreter—this is one of the reasons that displaying dates
and times is a good starting place for beginners.
NOTE To start writing the script, add the following line after the first <script>
Notice the semicolon at the end tag. Be sure to use the same combination of capital and lowercase
of the code snippet creating letters in your version because JavaScript commands and variable
a variable called now. This names are case sensitive.
semicolon tells the browser
now = new Date();
that it has reached the end of
a statement. Semicolons are
optional, but using them helps This statement creates a variable called now and stores the current date
you avoid some common errors. and time in it. This statement and the others you will use in this script
We’ll use them throughout this use JavaScript’s built-in Date object, which enables you to conveniently
book for clarity. handle dates and times. You’ll learn more about working with dates in
Chapter 17, “Using JavaScript Functions and Objects.”
Displaying Time with JavaScript 85
Creating Output
You now have two variables—localtime and utctime—which contain
the results we want from our script. Of course, these variables don’t do
us much good unless we can see them. JavaScript includes several ways
to display information, and one of the simplest is the document.write
statement.
These statements tell the browser to add some text to the web page
containing your script. The output will include some brief strings
introducing the results, and the contents of the localtime and utctime
variables.
Notice the HTML elements, such as <p> and <strong>, within the
quotation marks—because JavaScript’s output appears within a web
page, it needs to be formatted using HTML.
86 CHAPTER 4: Understanding JavaScript
<html lang="en">
<head>
<title>Displaying Times and Dates</title>
</head>
<body>
<h1>Current Date and Time</h1>
<script type="text/javascript">
now = new Date();
localtime = now.toString();
utctime = now.toGMTString();
document.write("<p><strong>Local time:</strong> "
+ localtime + "</p>");
document.write("<p><strong>UTC time:</strong> " + utctime
+ "</p>");
</script>
</body>
</html>
Now that you have a complete HTML document, save it with an .html
extension.
Testing the Script 87
FIGURE 4.2
Using JavaScript to display the
date and time.
These statements load the hours, mins, and secs variables with the
components of the time using JavaScript’s built-in date functions.
After the hours, minutes, and seconds are in separate variables, you
can create document.write statements to display them:
document.write("<p><strong>");
document.write(hours + ":" + mins + ":" + secs);
document.write("</p></strong>");
The first statement displays an HTML <h2> header tag to display the
clock as a second-level header element. The second statement displays
the hours, mins, and secs variables, separated by colons, and the third
adds the closing </h2> tag.
You can add the preceding statements to the original date and time
script to add the large clock display. Listing 4.5 shows the complete
modified version of the script.
LISTING 4.5 The Date and Time Script with Large Clock Display
<!DOCTYPE html>
<html lang="en">
<head>
<title>Displaying Times and Dates</title>
</head>
<body>
<h1>Current Date and Time</h1>
<script type="text/javascript">
now = new Date();
localtime = now.toString();
utctime = now.toGMTString();
document.write("<p><strong>Local time:</strong> "
+ localtime + "</p>");
document.write("<p><strong>UTC time:</strong> " + utctime
+ "</p>");
hours = now.getHours();
mins = now.getMinutes();
secs = now.getSeconds();
document.write("<h2>");
document.write(hours + ":" + mins + ":" + secs);
Testing the Script 89
document.write("</h2>");
</script>
</body>
</html>
Now that you have modified the script, save the HTML file and open
the modified file in your browser. If you left the browser running, you
can simply use the Reload button to load the new version of the script.
Try it and verify that the same time is displayed in both the upper
portion of the window and the new large clock. Figure 4.3 shows the
results.
FIGURE 4.3
Displaying the modified Date and
Time script.
Save your HTML document again and load the document into the
browser. Depending on the browser version you’re using, one of two
things will happen: Either an error message will be displayed, or the
script will simply fail to execute.
FIGURE 4.4
Showing an error in the JavaScript
console in Chrome.
Summary 91
FIGURE 4.5
Chrome helpfully points out the
offending line.
Summary
During this chapter, you’ve learned what web scripting is and what
JavaScript is. You’ve also learned how to insert a script into an
HTML document or refer to an external JavaScript file, what sorts of
things JavaScript can do, and how JavaScript differs from other web
languages. You also wrote a simple JavaScript program and tested it
using a web browser. You also learned how to modify and test scripts,
and what happens when a JavaScript program runs into an error.
In the process of writing this script, you have used some of JavaScript’s
basic features: variables, the document.write statement, and functions
for working with dates and times.
92 CHAPTER 4: Understanding JavaScript
Q&A
Q. Do I need to test my JavaScript on more than one browser?
A. In an ideal world, any script you write that follows the standards for
JavaScript will work in all browsers, and 98% of the time (give or take)
that’s true in the real world. But browsers do have their quirks, and you
should test your scripts in Chrome, Internet Explorer, and Firefox at a
minimum.
Q. When I try to run my script, the browser displays the actual script in
the browser window instead of executing it. What did I do wrong?
A. This is most likely caused by one of three errors. First, you might be
missing the beginning or ending <script> tags. Check them, and verify
that the first reads <script type="text/javascript">. Second, your
file might have been saved with a .txt extension, causing the browser
to treat it as a text file. Rename it to .htm or .html to fix the problem.
Third, make sure your browser supports JavaScript, and that it is not
disabled in the Preferences dialog.
Q. Why are the <strong> and <br /> tags allowed in the statements
to print the time? I thought HTML tags weren’t allowed within the
<script> tags.
Workshop
The workshop contains quiz questions and exercises to help you
solidify your understanding of the material covered. Try to answer all
questions before looking at the “Answers” section that follows.
Quiz
1. When a user views a page containing a JavaScript program, which
machine actually executes the script?
a. The user’s machine running a web browser
b. The web server
c. A central machine deep within Netscape’s corporate offices
Answers
1. a. JavaScript programs execute on the web browser. (There is actually a
server-side version of JavaScript, but that’s another story.)
2. b. Any text editor can be used to create scripts. You can also use a
word processor if you’re careful to save the document as a text file with
the .html or .htm extension.
94 CHAPTER 4: Understanding JavaScript
Exercises
▶ Add a millisecond field to the large clock. You can use the
getMilliseconds function, which works just like getSeconds but
returns milliseconds.
▶ Modify the script to display the time, including milliseconds, twice.
Notice whether any time passes between the two time displays when
you load the page.
INDEX
history, 2, 372-374 built-in objects, 356, 425, 430-433 error messages, displaying, 90
HTML development, 2 date object, 438 Sources panel, debugging
images, auto loading, 21 converting date formats, 440 JavaScript, 114-117
information, reading via JavaScript creating, 438 clarity, coding for, 653-654
dishonest browsers, 517-518 local time values, 440 Classic FTP client
displaying information, reading date values, 439 server connections, 14
515-516 setting date values, 439 website connections, 12-13
Internet Explorer, 9, 470 time zones, 440 clear property (CSS) and text
links, opening in new browser definitions, extending, 431 property, 281
windows, 181 math object, 434-435 client-side scripting, 338, 349
lists, displaying, 140 generating random numbers, clip art, 199
margins, 287-288 435-438 closing/opening browser windows,
non-Internet Explorer event rounding decimal 491-493
properties, 470 numbers, 434 closing slashes (HTML tags), 33
non-JavaScript browsers, 520 truncating decimal closing tags (HTML), 30
avoiding errors, 522-525 numbers, 435 cm value (CSS height/width
detecting, 521 bulleted lists, 142 properties), 63
JavaScript optionality, 521-522 buttons, creating, 206-208 code (source), viewing via Developer
<noscript> tags, 521 buying domain names, 7 Tools, 110
non-viewable window areas, 316 color
Opera, 9 140 cross-browser color
names, 192
padding, 287-288
analogous color schemes, 191
plug-ins, defining, 231 C background color
popularity of, 26
case-sensitivity, JavaScript background-color style
pop-up windows, 181 property, 223
progressive enhancement, syntax, 360
case statements (JavaScript), 453 CSS and, 195-198
506-507
categorizing elements, 44 best practices, 190-191
QuickTime support, 233
CD-ROM, transferring photos to, 200 border color (tables) and CSS,
Safari, 9 195-198
search engines, 521 cells (tables)
color property (CSS), 67
sensing. See feature sensing creating, 146
color style rule (CSS), 129
servers, basic browser server sizing, 151-153
color theory, 191
interaction, 3-5 Champeon, Steve, 507
color wheel, 191
text, adjusting font size, 21, 60 character entity, 123
Colorblind Web Page Filter
websites checkboxes (forms), 621-623 tool, 198
comparing, 26 child objects (JavaScript), 426 complementary color
testing, 8-9, 26 children (DOM), 377 schemes, 191
windows child tags. See nested tags (HTML) graphics, adjusting color in, 204
creating, 490-491 Chrome (Google), 9 hexadecimal color codes,
moving, 493-495 Console, debugging JavaScript, 192-195
opening/closing, 491-493 111-112 links and, 192
resizing, 493-495 Developer Tools monitors and, 192
timeouts, 495-497 CSS Inspector, 108-109 names and case sensitivity, 192
debugging JavaScript, 111-117 tables and, 155-156
HTML Inspector, 101-103
664 color
properties of, 369 dotted value (CSS border-style <embed /> element, 237
text, writing within properties), 65 embedding multimedia files, 235-238
documents, 371 double value (CSS border-style Ember JavaScript framework, 538
document roots, 14-18 properties), 65 emphasized (italic) text, 67, 125-126
document.write statements doɃwhile loops (JavaScript), 457 empty tags (HTML), 30
(JavaScript), 80, 85 draggable() widget (jQuery UI library), error handling
Dojo JavaScript library, 534 575-578, 581-584
JavaScript best practices,
DOM (Document Object Model), 367 droppable() widget (jQuery UI library), 510-511
children, 377 575, 580-584
JavaScript scripts, 89-91
jQuery JavaScript library and, 544 dynamic websites, 337
non-JavaScript browsers, 522-525
layers client-side scripting, 338
error messages, displaying, 90
controlling positioning via DOM, 345-346
errors, avoiding, 524
JavaScript, 381-385 images, changing based on user
interaction, 346-347 escaping loops (JavaScript), 458
creating, 380-381 ESPN.com, website organization, 646
moveable layers, 381-385 JavaScript
changing images based on European languages, formatting text
nodes, 377 for, 122-124
user interaction, 346-347
document node, 379 event handlers, 465
comments in HTML files, 340
methods of, 380 $(document).ready handler (jQuery
displaying random content in
properties, 378-379 HTML files, 340-344 JavaScript library), 542-543
objects, 425 scripting in HTML files, creating, 466-467
anchor objects, 372 338-339 defining, 467-468
document objects, server-side scripting, 338 event objects, 466, 469-470
369-372, 375 VBScript, 338 functions and, 594
hiding/showing, 385-387 JavaScript and, 81-82, 357,
history objects, 372-374 360, 507
link objects, 371, 375 best practices, 358
location objects, 374-375 E cross-browser scripting,
methods, 368 508-509
naming, 368 editors (blog), 20 W3C event model, 508
parents, 377 effects (JavaScript), 83, 534-536 jQuery JavaScript library, 542-543,
properties, 368 553-554
elastic layouts, 334
referencing, 368 keyboard events, 474-476
elements
showing/hiding, 385-387 mouse events
block-level elements, aligning text
siblings, 378 in, 136-137 mousestatus function, 473
window objects, 368, 489-499 categorizing, 44 onClick, 471-474, 478-484
parents, 377 definition of, 56 onDblClick, 472
readiness and, 542 flow content, 44 onMouseDown, 472-474
siblings, 378 form elements, grouping, 619-620 onMouseOut, 471
structure of, 376-377 else keyword (JavaScript), 448-452 onMouseOver, 471
text <em> tags (HTML), 125-126 onMouseUp, 472-474
adding to web pages, 389-391 email addresses rollover images, 471
modifying web pages, 387-388 email address encoders, 180 multiple event handlers, 468
DOM objects (JavaScript), 356 linking to, 179-180 onLoad events, 477
domain names, purchasing, 7 validating, 629 onUnload events, 478
parentheses and, 594
forms 667
quotation marks and, 466 infinite loops, 457-458 border property, 64-65
syntax of, 466 loops border-right property, 64-65
Yahoo! UI Library, 509 break statements, 458 border-style property, 64-65
event objects, 466, 469-470 continue statements, 459 border-top property, 64-65
expressions (JavaScript), 399 escaping, 458 border-width property, 64
external scripts (JavaScript), 81 switch statements, using multiple color property, 67
external style sheets (CSS), 56-62 conditions, 452-453 font-family property, 66
while loops, 456-457 font property, 67
flowing text, 280-281 font-size property, 66
fluid layouts. See liquid layouts font-style property, 66
F folders (web content), 169-171 font-weight property, 66
fonts (text) line-height property, 67
feature sensing, 509, 519 Arial font, 129 padding property, 67
Fetch FTP client, 12 CSS text-align property, 66-67
finding substrings (JavaScript), 407 color style rule, 129 text-decoration property, 67
Firefox web browser, 9, 90 font property, 67 text-indent property, 66
FireFTP FTP client, 11-12 font-family property, 66 style sheets, 56, 60
FireZilla FTP client, 12 font-family style rule, 129 text
fixed layouts, 316-317 font-size property, 66 aligning text, 135
fixed/liquid hybrid layouts, 321, font-size style rule, 129 boldface text, 125-126
330-332 font-style property, 66 bulleted lists, 142
columns font-weight property, 66 customizing fonts in HTML,
defining in layouts, 323-325 font weight style rule, 126 128-132
height, 326-330 <font> tags (HTML), 122, 128 definition lists, 138-140, 286
minimum width, setting, 325-326 foreign languages, 122-124 emphasized text, 126
structure of, 321-323 HTML, customizing in, 128-132 foreign languages, 122-124
Flickr, 212-214 resumes, creating, 130-132 italic (emphasized) text,
float property (CSS), 249, sans-serif font, 129 125-126
262-266, 281 sizing, 21, 60 multitiered lists, 144-145
flow content elements, 44 special characters, 122-124 nested lists, 140-141, 286
flow control (JavaScript), 445 Times Roman font, 129 older HTML tags, 122
break statements, 458 web fonts, 132-134 ordered lists, 138-140, 286
case statements, 453 <footer> tags, HTML5, 25, 37-41, outlines, 141-142
continue statements, 459 49-50 resumes, creating, 130-132
do…while loops, 457 foreign languages, formatting text for, special characters, 122-124
for…in loops, 459-462 122-124 subscript text, 126
for loops, 453-455 for loops (JavaScript), 453-455 superscript text, 126
if statements, 445 for…in loops (JavaScript), 459-462 unordered lists, 138-140, 286
conditional expressions, formatting web fonts, 132-134
446-449 CSS formatting properties, 63 web pages, creating, 34
conditional operators, 446-447 background-color property, 66 forms, 611
else keyword, 448-452 border-bottom property, 64-65 checkboxes, 621-623
logical operators, 447-448 border-color property, 64-65 creating, 612-617
testing multiple conditions, border-left property, 64-65
450-452
668 forms
loading web content, timing of, 21 math functions, 435-438 moveable layers (DOM), 381-385
local time values, date object random numbers, generating, moving browser windows, 493-495
(JavaScript) and, 440 435-438 Mozilla Firefox web browser. See
local variables (JavaScript), 396 methods Firefox web browser
localtime variable (JavaScript), 85 DOM nodes, 379-380 multimedia, 242
location objects (DOM), 374-375 DOM objects, 368 audio files, HTML5 playback,
logical operators (JavaScript), document objects, 371 238-239
447-448 history objects, 372 creating, 232
loops (JavaScript), 357 location objects, 375 defining, 189
break statements, 458 JavaScript objects, 355-356, 426 embedding files, 235-238
continue statements, 459 defining, 428-429 linking to files, 231-233
continuing, 459 get methods, 439 MIME types, 236
do…while loops, 457 prototypes, 432-433 <object> element, 235-237
escaping, 458 string objects and, 433 QuickTime support, 233
for…in loops, 459-462 Microsoft Internet Explorer web streaming files, 235
for loops, 453-455 browser. See Internet Explorer video files, HTML5 playback,
infinite loops, 457-458 MIME types, multimedia files, 236 238-241
while loops, 456-457 mm value (CSS height/width multiple event handlers, 468
LunarPages web hosting provider, 7 properties), 64 multitiered lists, 144-145
modifying MVC (Model-View-Controller)
JavaScript scripts, 87-89 JavaScript framework pattern, 537
text in web pages, 387-388
M modulo operators (JavaScript), 437
monitors
managing color and, 192 N
domain names, 7 resolution, 207
HTML files, 16-19 mouses naming
web page headings, 34-35 events and event handling anchor tags, 173
websites mousestatus function, 473 DOM objects, 368
coding clarity, 653-654 onClick event handler, files with HTML tags, 27
comments, 652-653 471-475, 478-484 form data, 618
documenting code, 652-653 onDblClick event handler, 472 JavaScript
indenting code, 653-654 onMouseDown event handler, functions, 361
maintainable code, 652-654 472-474 objects, 361
version control, 654-656 onMouseOut event variables, 361, 395-396
handler, 471 NaN (Not a Number), 402
margins
onMouseOver event <nav> tags, HTML5, 25, 37-41, 46-47
browsers and, 287-288 handler, 471
CSS box model, 270 navigating websites, 82
onMouseUp event handler, navigation lists
margin property (CSS), 249-257 472-474
marked-up text, 3 horizontal navigation, 307-311
mouse interaction widget (jQuery
math object (JavaScript) UI library), 574-575 primary navigation, 296
decimal numbers rollover images, 471 regular lists vs, 296
rounding, 434 secondary navigation, 296
truncating, 435
parseFloat() function (JavaScript) 677
vertical navigation, 296-299 link objects, 371, 375 operators (JavaScript), precedence of,
multilevel vertical navigation, location objects, 374-375 399-400
302-306 methods, 368, 371-372, 375 Opera web browser, 9
single-level vertical navigation, naming, 368 optional JavaScript coding, 521-522
300-302 parents, 377 ordered lists, 138-140, 286
nested lists, 140-141, 286 properties, 368-369, 372-375 organizing
nested tags (HTML), 141 referencing, 368 HTML files
nodes (DOM), 377-378 showing/hiding, 385-387 document roots, 16-18
document node, 379 siblings, 378 index pages, 18-19
methods of, 380 window objects, 368, 489-499 web content, 169-170
properties, 378-379 JavaScript web page headings, 34-35
none values (CSS) built-in objects, 356, 425, websites, 641
border-style properties, 65 430-434, 438-440 Amazon.com, 648-649
display property, 63 child objects, 426 BAWSI.org, 651
non-viewable window areas creating, 426 ESPN.com, 646
(browsers), 316 custom objects, 356 larger websites, 648-651
<noscript> tag (JavaScript), detecting date objects, 438-440 Peet’s Coffee & Tea, 649
non-JavaScript browsers, 521
defining, 427-428 simple websites, 644-648
Notepad, creating HTML files, 27
instance creation, 429-430 single-page websites, 642-643
null values (JavaScript), 401
math objects, 434-438 Outline tool (HTML5), 43
numbers
methods, 355-356, 426-429, outlines, building via lists, 141-142
arithmetic mean, 437 432-433, 439 outset value (CSS border-style
decimal numbers naming, 361 properties), 65
rounding, 434 properties, 355, 426, 432-433 overflow property (CSS) and
truncating, 435 prototypes, 432-433 text flow, 281
numeric arrays (JavaScript), 408, scripting, 427-430 overlapping elements, 278-280
411-413 overusing JavaScript, 504-505
string objects, 402-404, 433
numeric data types
(JavaScript), 400 onClick event handler, 471-474, 478
random numbers, generating, onclick event (JavaScript) and mouse
435-438 actions, 478-484
onDblClick event handler, 472 P
online resources, CSS
browser support, 62 <p> tags, 31-33
reference guide, 57 padding
O browsers and, 287-288
onLoad events, 477
<object> element, embedding onMouseDown event handler, CSS box model, 270
multimedia files, 235-237 472-474 padding property (CSS), 67, 249,
objects onMouseOut event handler, 471 257-261
DOM, 425 onMouseOver event handler, 471 paragraphs, web page creation, 32-33
anchor objects, 372 onMouseUp event handler, 472-474 parameters (JavaScript functions),
onUnload events, 478 354, 420
document objects,
369-372, 375 opening/closing browser windows, parent folders, 171
hiding/showing, 385-387 491-493 parents (DOM), 377
history objects, 372-374 opening tags (HTML), 30 parseFloat() function (JavaScript), 402
678 parseInt() function (JavaScript)
debugging HTML, 98-100, hexadecimal color codes, labeling form data, 618-619
103-105 192-195 naming form data, 618
debugging JavaScript, 111-117 names and case passwords, 617
HTML Inspector, 100, 103-105 sensitivity, 192 pull-down pick lists, 624-626
viewing source code, 110 using, 190-191 radio buttons, 623-624
development of, 2 W3C color standards, 192 scrolling lists, 624-626
distributing, 20 comparing, 26 selection lists, 624-626
Firefox, 9 creating, 2-3 sending, 613
graceful degradation, 506 ASCII text, 27, 34 submitting form data, 631-632
helper applications, defining, 231 comparing web content HTML text fields, 627-628
history of, 2 codes, 36
text input, 617-618
HTML development, 2 formatting text, 34
user input, 617-618
images, auto loading, 21 HTML tags, 27-33
graphics
Internet Explorer, 9 indenting text, 34
adjusting color, 204
lists, displaying, 140 line breaks, 32-33
Adobe Photoshop, 198
Opera, 9 organizing content via
headings, 34-35 aligning graphics, 216-220
plug-ins, defining, 231 animated graphics, 211-212
overview of, 29
popularity of, 26 background graphics, 223-224
paragraphs, 32-33
progressive enhancement, banners, 206-208
506-507 plain, text, 27, 34
templates, 31 buttons, 206-208
QuickTime support, 233 choosing software, 198
Safari, 9 CSS box model, 269
borders, 270 clip art, 199
servers, basic browser server compression, 199
interaction, 3-5 content, 270
lists and, 286-290 copyrights and, 199
text, adjusting font size
settings, 21 margins, 270 Creative Commons
licenses, 199
websites padding, 270
cropping, 200-202
comparing, 26 sizing elements, 270-272
file sizes, 199
testing, 8-9, 26 delivering, 3-5
Flickr, 212-214
web content directories, 169-170
.GIF, 208-212
absolute addresses, 170-171 floating elements, 249
GIMP, 198, 201-208
aligning float property (CSS), 249,
262-266, 281 Google Images, 212
align property (CSS), 249
folders, 169-171 Google Picasa, 199
text-align property (CSS), 262
forms, 611 grabbing from web pages, 199
vertical-align property
(CSS), 262 accessing elements via graphics, placing on web
JavaScript, 633 pages, 212-214
clear property (CSS) and
text flow, 281 checkboxes, 621-623 height, 216
color creating, 612-617 imagemaps, 225-230
140 cross-browser color displaying data in pop-up .JPEG, 205, 209-211
names, 192 windows, 633-635 Pixlr, 199
best practices, 190-191 grouping elements, 619-620 .PNG, 209
Colorblind Web Page Filter hidden data, 620 Red Eye Removal, 204
tool, 198 JavaScript events, 632 republishing, 214
686 web content