JavaScript: The Definitive Guide: The Definitive Guide [NOOK Book]


This Fifth Edition is completely revised and expanded to cover JavaScript as it is used in today's Web 2.0 applications. This book is both an example-driven programmer's guide and a keep-on-your-desk reference, with new chapters that explain everything you need to know to ...

See more details below
JavaScript: The Definitive Guide: The Definitive Guide

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$22.99 price
(Save 42%)$39.99 List Price


This Fifth Edition is completely revised and expanded to cover JavaScript as it is used in today's Web 2.0 applications. This book is both an example-driven programmer's guide and a keep-on-your-desk reference, with new chapters that explain everything you need to know to get the most out of JavaScript, including:

  • Scripted HTTP and Ajax
  • XML processing
  • Client-side graphics using the canvas tag
  • Namespaces in JavaScript--essential when writing complex programs
  • Classes, closures, persistence, Flash, and JavaScript embedded in Java applications

Part I explains the core JavaScript language in detail. If you are new to JavaScript, it will teach you the language. If you are already a JavaScript programmer, Part I will sharpen your skills and deepen your understanding of the language.

Part II explains the scripting environment provided by web browsers, with a focus on DOM scripting with unobtrusive JavaScript. The broad and deep coverage of client-side JavaScript is illustrated with many sophisticated examples that demonstrate how to:

  • Generate a table of contents for an HTML document
  • Display DHTML animations
  • Automate form validation
  • Draw dynamic pie charts
  • Make HTML elements draggable
  • Define keyboard shortcuts for web applications
  • Create Ajax-enabled tool tips
  • Use XPath and XSLT on XML documents loaded with Ajax
  • And much more

Part III is a complete reference for core JavaScript. It documents every class, object, constructor, method, function, property, and constant defined by JavaScript 1.5 and ECMAScript Version 3.

Part IV is a reference for client-side JavaScript, covering legacy web browser APIs, the standard Level 2 DOM API, and emerging standards such as the XMLHttpRequest object and the canvas tag.

More than 300,000 JavaScript programmers around the world have madethis their indispensable reference book for building JavaScript applications.

"A must-have reference for expert JavaScript programmers...well-organized and detailed."
-- Brendan Eich, creator of JavaScript

Geared toward JavaScript programmers, this book provides an excellent programmer's guide and reference manual for JavaScript 1.2. It includes a thorough description of the core JavaScript language and a detailed reference section.

Read More Show Less

Editorial Reviews

From Barnes & Noble
The Barnes & Noble Review
Over the past few years, the JavaScript language has matured. Not only is JavaScript now an international standard (called ECMAScript), the standard itself is in its third, refined version. Conformant implementations are available in several leading browsers, from Microsoft Internet Explorer 6 to Mozilla; and open source versions are available to be incorporated into any application that can benefit from a scripting language.

All this is to say that JavaScript is more useful than ever, and the JavaScript you use now can be relied upon (at least as much as anything in the computer industry ) to remain stable for years to come. It's worth your time to become a more capable JavaScript programmer -- and David Flanagan's JavaScript: The Definitive Guide, Fourth Edition may be your best tool for achieving that goal.

Well-known as "The Rhino Book" for its cover, JavaScript: The Definitive Guide has long been an outstanding resource for JavaScript programmers. Flanagan writes with discipline and clarity, and his book combines excellent tutorial coverage with a detailed reference that documents the classes, methods, and properties defined by the core JavaScript language.

But a lot's changed since the 1998 edition. And if you got involved with JavaScript at the heat of the web gold rush, a lot's changed since whatever JavaScript book you rely on was written. Here's just some of what's new and different in this book.

First of all, Flanagan's thoroughly updated his coverage to reflect JavaScript 1.5 and the aforementioned ECMA-262 third edition standard. Previous editions had a heavy focus on Netscape's implementation of JavaScript; that will obviously no longer do, so Flanagan has moved to a focus on the official standard. Since browser conformance has improved significantly, this book will help you write code that'll survive pretty much any browser you throw at it. (The reference section carefully specifies when each language element was introduced, and which versions of the standard support it.)

Flanagan's reorganized the book. For one thing, core language coverage has been separated with coverage of using JavaScript in client-side browsers, recognizing that many JavaScript developers nowadays aren't working in classic web browser environments. More important, he's moved the coverage of the W3C's DOM implementation into a section of its own, and substantially expanded that coverage. (Both DOM Level 2 and Level 1 are covered, with Level 0 coverage kept for backward compatibility.)

JavaScript: The Definitive Guide, Fourth Edition begins with an overview of what JavaScript can and cannot do, including some lingering myths about the language (many still view it as purely a simple scripting language, and are surprised by its depth when they attempt to perform complex tasks with it.) Next, Flanagan reviews the fundamentals of JavaScript 1.5: its lexical structure, data types and values, variables, expressions, operators, and statements.

If you're an experienced Java, C++, or C programmer, much of Section I will be familiar: JavaScript was designed to help developers leverage existing skills. Section II, however, focuses on stuff that's handled significantly differently in JavaScript. Here, Flanagan covers functions, objects, arrays, and pattern matching with regular expressions. He also introduces several advanced features, notably JavaScript's automatic data type conversion, garbage collection, lexical scoping, and function constructors.

Next, Flanagan focuses on client-side JavaScript. He shows how JavaScript integrates with web browsers; introduces the Window object and JavaScript's event-driven programming model; and shows how to use the Document Object to expose an HTML document's contents to JavaScript code. The book includes chapters on forms and form elements; cookies; and scripting CSS/DHTML to manipulate the style, appearance, and position of HTML document elements.

Notwithstanding Microsoft's dominance, it's still a diverse world out there. Flanagan shows how to avoid, minimize, and mitigate browser incompatibilities, introducing techniques for testing features, implementing platform-specific workarounds, and testing compatibility with server-side scripts. There's coverage of security, and a quick look at using Java with JavaScript. And the 300-page reference? Invaluable.

You'll live happily with this book for a long time. (Bill Camarda)

Bill Camarda is a consultant, writer, and web/multimedia content developer with nearly 20 years' experience in helping technology companies deploy and market advanced software, computing, and networking products and services. He served for nearly ten years as vice president of a New Jersey–based marketing company, where he supervised a wide range of graphics and web design projects. His 15 books include Special Edition Using Word 2000 and Upgrading & Fixing Networks For Dummies®, Second Edition.

Read More Show Less

Product Details

  • ISBN-13: 9780596554477
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 8/17/2006
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 5
  • Pages: 1032
  • Sales rank: 641,599
  • File size: 9 MB

Meet the Author

David Flanagan is a computer programmer who spends most of his time writing about JavaScript and Java. His books with O'Reilly include Java in a Nutshell, Java Examples in a Nutshell, Java Foundation Classes in a Nutshell, JavaScript: The Definitive Guide, and JavaScript Pocket Reference. David has a degree in computer science and engineering from the Massachusetts Institute of Technology. He lives with his wife and children in the U.S. Pacific Northwest bewteen the cities of Seattle, Washington and Vancouver, British Columbia. David has a blog at

Read More Show Less

Read an Excerpt

Chapter 17: The Document Object Model

A document object model (DOM) is an application programming interface (API) for representing a document (such as an HTML document) and accessing and manipulating the various elements (such as HTML tags and strings of text) that make up that document. JavaScript-enabled web browsers have always defined a document object model; a web-browser DOM may specify, for example, that the forms in an HTML document are accessible through the forms[] array of the Document object.

In this chapter, we'll discuss the W3C DOM, a standard document object model defined by the World Wide Web Consortium and implemented (at least partially) by Netscape 6 and Internet Explorer 5 and 6. This DOM standard1 is a full-featured superset of the traditional web-browser DOM. It represents HTML (and XML) documents in a tree structure and defines properties and methods for traversing the tree and examining and modifying its nodes. Other portions of the standard specify techniques for defining event handlers for the nodes of a document, working with the style sheets of a document, and manipulating contiguous ranges of a document.

This chapter begins with an overview of the DOM standard and then describes the core portions of the standard for working with HTML documents. The discussion of the core standard is followed by short sections that explain the DOM-like features of Internet Explorer 4 and Netscape 4. The chapter ends with an overview of two optional parts of the DOM standard that are closely related to the core. Later chapters cover advanced DOM features for working with style sheets and events.

An Overview of the DOM

The DOM API is not particularly complicated, but before we can begin our discussion of programming with the DOM, there are a number of things you should understand about the DOM architecture.

Representing Documents as Trees

HTML documents have a hierarchical structure that is represented in the DOM as a tree structure. The nodes of the tree represent the various types of content in a document. The tree representation of an HTML document primarily contains nodes representing elements or tags such as <body> and <p> and nodes representing strings of text. An HTML document may also contain nodes representing HTML comments.2 Consider the following simple HTML document:

    <title>Sample Document</title>
    <h1>An HTML Document</h2>
    <p>This is a <i>simple</i> document.

The DOM representation of this document is the tree pictured in Figure 17-1.

If you are not already familiar with tree structures in computer programming, it is helpful to know that they borrow terminology from family trees. The node directly above a node is the parent of that node. The nodes one level directly below another node are the children of that node. Nodes at the same level, and with the same parent, are siblings. The set of nodes any number of levels below another node are the descendants of that node. And the parent, grandparent, and all other nodes above a node are the ancestors of that node.


The DOM tree structure illustrated in Figure 17-1 is represented as a tree of various types of Node objects. The Node interface3 defines properties and methods for traversing and manipulating the tree. The childNodes property of a Node object returns a list of children of the node, and the firstChild, lastChild, nextSibling, previousSibling, and parentNode properties provide a way to traverse the tree of nodes. Methods such as appendChild( ), removeChild( ), replaceChild( ), and insertBefore( ) enable you to add and remove nodes from the document tree. We'll see examples of the use of these properties and methods later in this chapter.

Types of nodes

Different types of nodes in the document tree are represented by specific subinterfaces of Node. Every Node object has a nodeType property that specifies what kind of node it is. If the nodeType property of a node equals the constant Node.ELEMENT_NODE, for example, you know the Node object is also an Element object and you can use all the methods and properties defined by the Element interface with it. Table 17-1 lists the node types commonly encountered in HTML documents and the nodeType value for each one.

Table 17-1: Common node types


nodeType constant

nodeType value



















The Node at the root of the DOM tree is a Document object. The documentElement property of this object refers to an Element object that represents the root element of the document. For HTML documents, this is the <html> tag that is either explicit or implicit in the document. (The Document node may have other children, such as Comment nodes, in addition to the root element.) The bulk of a DOM tree consists of Element objects, which represent tags such as <html> and <i>, and Text objects, which represent strings of text. If the document parser preserves comments, those comments are represented in the DOM tree by Comment objects. Figure 17-2 shows a partial class hierarchy for these and other core DOM interfaces.


The attributes of an element (such as the src and width attributes of an <img> tag) may be queried, set, and deleted using the getAttribute( ), setAttribute( ), and removeAttribute( ) methods of the Element interface.

Another, more awkward way to work with attributes is with the getAttributeNode( ) method, which returns an Attr object representing an attribute and its value. (One reason to use this more awkward technique is that the Attr interface defines a specified property that allows you to determine whether the attribute is literally specified in the document, or whether its value is a default value.) The Attr interface appears in Figure 17-2, and it is a type of node. Note, however, that Attr objects do not appear in the childNodes[] array of an element and are not directly part of the document tree in the way that Element and Text nodes are. The DOM specification allows Attr nodes to be accessed through the attributes[] array of the Node interface, but Microsoft's Internet Explorer defines a different and incompatible attributes[] array that makes it impossible to use this feature portably....

Read More Show Less

Table of Contents

1 Introduction to JavaScript 1
2 Lexical structure 15
3 Datatypes and values 21
4 Variables 49
5 Expressions and operators 59
6 Statements 83
7 Objects and arrays 106
8 Functions 124
9 Classes, constructors, and prototypes 150
10 Modules and namespaces 183
11 Pattern matching with regular expressions 199
12 Scripting Java 213
13 JavaScript in Web browsers 235
14 Scripting browser Windows 270
15 Scripting documents 298
16 Cascading style sheets and dynamic HTML 345
17 Events and event handling 388
18 Forms and form elements 437
19 Cookies and client-side persistence 456
20 Scripting HTTP 478
21 JavaScript and XML 502
22 Scripted client-side graphics 530
23 Scripting Java applets and Flash movies 573
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 12 Customer Reviews
  • Anonymous

    Posted February 10, 2007

    Updated for the latest browsers and technology

    This 5th edition contains all the things you grew to love about the previous editions, updated for the latest browsers. As an addition to the previous versions, I found this edition contained better information on CSS and JavaScript, XML and JavaScript, and of course has several excellent sections on HTTP scripting (AJAX), as well as JavaScript and graphics. Like its predecessor, this book contains the excellent introduction to the core JavaScript library, which hasn¿t changed much from previous editions (at least to my eye). The client-side JavaScript section is where I noticed the most changes. This updated section contains a great refresher of CSS, identifies ¿quirks mode¿ in IE and other browsers, and gives some excellent examples of modifying CSS via JavaScript. The next section that appears new to me is the Scripting HTTP section, which is an excellent introduction to the world of AJAX. In this section, the author describes how to perform both synchronous and asynchronous requests via JavaScript, how to handle the results, and differences between different browsers. I also came across several (new to me) sections on manipulating graphics with JavaScript. In these sections, the author discusses creating graphics with CSS, SVG, and VML. Again, the examples are clear and easy to follow. Again, like the previous editions, the book also contains a Core JavaScript Reference as well as a Client Side JavaScript Reference. These sections identify each method or property of each object, provide a description, and illustrate usage with a brief example. These sections have all been updated in this version to show what JavaScript/ECMAScript version the method or property first appeared, or whether it is a feature supported only by a subset of browsers. This is an invaluable reference when creating cross-browser JavaScript. All in all, I was very pleased with the updates to this edition. I think especially if you are looking for a good AJAX reference, the updates to this book make it well worth your time.

    2 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted March 28, 2010

    Excellent resource

    Best reference I've come across for JavaScript.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted August 29, 2009

    No text was provided for this review.

  • Anonymous

    Posted October 15, 2010

    No text was provided for this review.

  • Anonymous

    Posted October 14, 2008

    No text was provided for this review.

  • Anonymous

    Posted April 28, 2009

    No text was provided for this review.

  • Anonymous

    Posted December 23, 2010

    No text was provided for this review.

  • Anonymous

    Posted November 9, 2008

    No text was provided for this review.

  • Anonymous

    Posted August 20, 2010

    No text was provided for this review.

  • Anonymous

    Posted July 23, 2011

    No text was provided for this review.

  • Anonymous

    Posted April 27, 2009

    No text was provided for this review.

  • Anonymous

    Posted January 25, 2009

    No text was provided for this review.

Sort by: Showing all of 12 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)