A B C D E F G H I J K L M N O P Q-R S T U V W X Y-Z

Symbols

[top]

&= (assignment) operator, 404

*= (assignment) operator, 404

^= (assignment) operator, 405

/= (assignment) operator, 404

-= (assignment) operator, 27, 404

%= (assignment) operator, 404

+= (assignment) operator, 27, 403-404

|= (assignment) operator, 405

<<= (assignment) operator, 405

>>= (assignment) operator, 405

>>>= (assignment) operator, 405

\ (backslash), 70

& (bitwise AND) operator, 404

| (bitwise OR) operator, 404

^ (bitwise XOR) operator, 404

~ (bitwise NOT) operator, 404

, (comma) operator, 406

/*...*/ comment syntax, 24

// comment syntax, 24

+ (concatenation) operator, 27-28, 403

?: (conditional) operator, 406

- - (decrement) operator, 26

/ (division) operator, 26, 403

= (equal) operator, 27, 404

== (equality) operator, 405

$() function (prototype.js), 309

$() operator (jQuery), 319

> (greater than) operator, 87, 405

>= (greater than or equal to) operator, 87, 405

++ (increment) operator, 26

<< (left shift) operator, 404

< (less than) operator, 87, 405

<= (less than or equal to) operator, 87, 405

&& (logical AND) operator, 89, 403

|| (logical OR) operator, 89, 403

! (logical NOT) operator, 74, 403

% (modulus) operator, 26, 403

* (multiplication) operator, 26, 403

<!——> notation, 23

!= (not equal) operator, 86, 405

>> (right shift) operator, 404

=== (strict equality) operator, 86, 405

!== (strict not equal) operator, 405

- (unary negation) operator, 26

>>> (zero-fill right shift) operator, 404

A

[top]

<a> element, 356

abort() method, 258

abs method, 407

abstraction, 220

accessing

browser history, 52-53

classes with className, 207-209

JSON data, 123-124

accordian widget, 343-344

accordion() method, 343-344

acos method, 407

ActionScript, JavaScript support in, 384

addEventListen() method, 146

Adobe Flash, 358-361

controlling with JavaScript, 359-361

methods, 359

Adobe tools, JavaScript support in, 383

advanced event handler registration

cross-browser implementation, 147-148

Microsoft method, 147

W3C method, 146-147

advantages of JavaScript, 8-9

Ajax

Ajax library

callback function, 276

goals, 274

HTTP GET and POST requests, 275-276

including in HTML page, 278-280

making Ajax calls, 276-277

myAjaxLib.js source code, 277-278

overview, 273

returning keyword META information from remote sites, 280-283

XMLHttpRequest instances, 274-275

application structure, 251-253

flow diagram, 255

server requests, 253-254

server responses, 254

XMLHttpRequest object, 253

callback functions, 264-265

canceling Ajax calls, 270

clock application, 267-269

debugging

Back button, 292-293

bookmarks, 293

browser caching of GET requests, 297

degradation, 294

escaping content, 297

feedback for users, 293-294

with Firebug, 287-290, 299

inappropriate use of Ajax, 295-296

with Internet Explorer, 290-292

links, 293

Permission Denied errors, 297

pop-up information, 295

search engine spiders, 294, 299

security, 296

testing across multiple platforms, 296

implementing with jQuery, 328

ajax() method, 330

get() method, 329

load() method, 329

post() method, 330

sample Ajax form with jQuery, 330-332

server requests

dealing with browser cache, 261-262

overview, 253-254

sending, 260-261

server status, monitoring

readyState property, 263

server response status codes, 264

XMLHttpRequest object

creating instances of, 256-258

methods, 258-260

overview, 253-256

properties, 258-259, 265-267

ajax() method, 330

ajax.js, 267-269

Ajax.PeriodicalUpdater class, 310-311

Ajax.Request class, 309

Ajax.Updater class, 309-310

alert dialogs, displaying, 49

alert() method, 14, 49

allowDrop() function, 375

altKey property (events), 143

ampersand (&), 404

anchor elements, 356

AND operators

& (bitwise AND), 404

&& (logical AND), 403

logical AND (&&), 89

animate() method, 324, 371

animated shooting game example, 242-245

animation

animated shooting game example, 242-245

animating elements with jQuery, 322

animate() method, 324

sample program, 325-327

sliding page elements, 323-324

transitions, 323

<canvas> element, 370-372

CSS3 transitions and transformations, 239-240, 246

DOM elements, 240-241

page elements, 236-237

frame rate, 236, 242

setInterval() method, 237, 246

setTimeout() method, 237, 246

performance optimization, 242

timers, 242

transparency, 238-239

anonymous functions, 107-108

appendChild() method, 187-188

appending child nodes, 187-188

arc() function, 371

arguments

explained, 40

multiple arguments, 40-42

arithmetic operators, 26-27, 403

array.html, 78-79

arrays

array manipulation sample script, 78-79

associative arrays, 80, 127

concatenating, 76

creating, 74-75

defining with JSON (JavaScript Object Notation), 128

definition of, 74

initializing, 75

length property, 75

methods

concat(), 75-76

indexOf(), 75-76

join(), 75-76

lastIndexOf(), 75-77

slice(), 75-77

sort(), 76-77

splice(), 76-77

toString(), 75-76

slicing, 77

sorting, 77

splicing, 77

<article> element, 366

<aside> element, 366

asin method, 407

assigning values to variables, 25

assignment operators, 404-405

associative arrays, 80, 127

assumptions, avoiding, 221

asterisk (*), 26, 403

atan method, 407

attachEvent function, 147

attr() method, 321

attributes (element)

editing, 191-192

reading, 179-180

attributes property (DOM nodes), 180

audio

formats, 353-354

playing with <audio> element, 369

streaming, 363

<audio> element, 369

autoplay attribute (<video> element), 367

.avi files, 354

avoiding

assumptions, 221

overuse of JavaScript, 217-218

B

[top]

Back button, debugging, 292-293

back() method, 53

backslash (\), 70

banner cycling script, 97-100

behavior layer, 223

best practices

assumptions, avoiding, 221

code reuse, 220-221

comments, 218-219

error handling, 227-228

feature detection, 226-227

graceful degradation, 221-222

naming conventions, 219-220

overuse of JavaScript, avoiding, 217-218

progressive enhancement, 222-223

unobtrusive JavaScript

converting code into, 228-231

explained, 223-226

bitwise operators, 404

bookListObject, 129-131

bookmarks, debugging, 293

Boolean values, 73-74

break command, 92-93

browser extensions

Firefox extensions, 395

Google Chrome extensions

extension to return airport information, 387-388

icon files, 388

manifest.json file, 388-389

popup.html file, 389-392

writing, 384-386

JavaScript support in, 383

packing, 393

browser plug-ins, 355-358

browser sniffing, 117

browsers

browser history, accessing, 52-53

browser extensions

Firefox extensions, 395

Google Chrome extensions, 384-392

JavaScript support in, 383

packing, 393

browser plug-ins, 355-358

browser sniffing, 117

browser wars, 9-10

cache, 261-262

feature detection, 116-118, 226-227

Firefox

DOM Inspector, 180-181

extensions, 395

Firebug, 100, 287-290, 299, 401

JavaScript support in, 384

Internet Explorer, 9

debugging Ajax with, 290-292

F12 Developer Tools, 100

JSON (JavaScript Object Notation) support, 123, 133

buttonReport() function, 41-42

C

[top]

cache (browser), 261-262

callback functions, 264-265, 276

calling functions, 38

CamelCase naming convention, 25, 220

canceling Ajax calls, 270

canPlayType() method, 368

<canvas> element, 370-372

capturing mouse events

onClick event handler, 30-31

onMouseOut event handler, 31-33

onMouseOver event handler, 31-33

caret (^), 404

Cascading Style Sheets. See CSS styles

case sensitivity, 25, 31

catch statement, 227-228

CDNs (Content Delivery Networks), 318

ceil() method, 59-60, 407

Celsius, converting to Fahrenheit, 28-29

changing

classes with className, 207-209

mouse cursor, 215

character strings, assigning to variable values, 25

checkform() function, 140

child nodes (DOM)

appending, 187-188

inserting, 188

removing, 191

replacing, 188-190

childNodes property (DOM nodes), 174-175

Chome extensions

extension to return airport information, 387-388

icon files, 388

JavaScript support in, 383

manifest.json file, 388-389

packing, 393

popup.html file

basic popup.html, 389-391

complete popup.html, 391-392

writing, 384-386

classes

accessing using className, 207-209

Ajax.PeriodicalUpdater, 310-311

Ajax.Request, 309

Ajax.Updater, 309-310

className property, 207-209

clearRect() method, 371

client-side programming, 8

clientX property (events), 143

clientY property (events), 143

clock application (Ajax), 267-269

cloneNode() method, 186-187

cltrlKey property (events), 143

code reuse, 104, 220-221

collections, NodeList, 174

comma (,) operator, 406

command chaining (jQuery), 324

comments

HTML comments, 23

JavaScript comments, 24

performance considerations, 24

writing, 218-219

comparison operators, 86-87, 405

compiled languages, 10

concat() method, 71-72, 75-76

concatenating

arrays, 76

strings, 27-28, 72

concatenation operator, 27-28

conditional (?:) operator, 406

conditional statements

if(), 85-86

testing for equality, 87-88

testing multiple conditions, 88

switch, 88-89

confirm() method, 50

confirmation dialogs, displaying, 50

constants, mathematical, 61

constructor functions, 108-110

Content Delivery Networks (CDNs), 318

continue statement, 101

control structures. See loops

controls attribute (<video> element), 367

converting

Celsius to Fahrenheit, 28-29

code into unobtrusive code, 228-231

strings

to numbers, 69

to uppercase/lowercase, 73

cookie property (document object), 156

cookieName value, 157

cookies

components, 157-158

cookieName value, 157

cookieValue value, 157

domain attribute, 157-158

expires attribute, 158

path attribute, 158

secure attribute, 158

definition of, 155-156

deleting, 162

document.cookie property, 156

escaping and unescaping data, 156-157

limitations of, 156

reading, 161-162

security, 166

setting multiple values in, 165-166

testing

cookies.js, 162-163

cookietest.html, 163-165

cookietest2.html, 164-165

writing, 158-161

cookies.js, 162-163

cookietest.html, 163-165

cookietest2.html, 164-165

cookieValue value, 157

cos method, 407

createCookie() function, 159-162

createElement() method, 185-186

createElementTextNode() method, 186

Crockford, Douglas, 401

cross-browser event handlers, 142-144, 147-148, 152

CSS (Cascading Style Sheets) styles, 201

advantages of, 201-202

changing classes using className, 207-209

CSS3 animations

transformations, 239-240, 246

transitions, 239-240, 246

DOM style property, 204-207

style declarations

placing, 204

syntax, 202-203

style properties, setting, 205-206

stylesheets

DOM styleSheets object, 209

enabling/disabling, 209-211

selecting, 211-214

switching, 209-211

cursor, changing, 215

customized widgets, 349

cycle() function, 98-99

cycling images on page, 97-100

D

[top]

data serialization, 124-126

data types

arrays

associative arrays, 80

associative arrays, simulating, 127

creating, 74-75

definition of, 74

initializing, 75

length property, 75

methods, 75-77

definition of, 67

JSON (JavaScript Object Notation) data types, 126

numbers

converting strings to, 69

floating-point numbers, 68

hexadecimal numbers, 68

infinity, 69-70

integers, 67-68

NaN (not a number), 69

natural numbers, 67

whole numbers, 67

strings

Boolean values, 73-74

converting to numbers, 69

definition of, 70

escape sequences, 70-71

maximum length of, 80

methods, 71-73

Date object

creating with a given date and time, 58

creating with current date and time, 57

methods, 408-410

reading date and time, 62-64

setting/editing dates and times, 58-59

time zones, 65

date picker widget, 344-346

datepicker() method, 345-346

datetime.js, 230

debugging, 94-96. See also error handling, 227-228

Ajax, 287

Back button, 292-293

bookmarks, 293

browser caching of GET requests, 297

degradation, 294

escaping content, 297

feedback for users, 293-294

with Firebug, 287-290, 299

inappropriate use of Ajax, 295-296

with Internet Explorer, 290-292

links, 293

Permission Denied errors, 297

pop-up information, 295

search engine spiders, 294, 299

security, 296

testing across multiple platforms, 296

debugging tools

Firebug, 401

JSLint, 401

declaring

CSS styles

placement of style declarations, 204

syntax, 202-203

direct instances, 104-108

decrement (- -) operator, 26

default actions (event handlers)

explained, 138

preventing, 138-141

degradation, graceful, 221-222, 294

delete operator, 406

deleteCookie() function, 162-163

deleting cookies, 162

deprecated status, 11

deserialization (JSON)

with eval() function, 123

with native browser support, 123, 133

with parse() function, 123

detachEvent function, 147

detecting browser features, 226-227

detecting features, 116-118

development

of JavaScript, 9

of jQuery, 333

dialogs, displaying

alert dialogs, 49

confirmation dialogs, 50

prompts, 50-51

direct instances, declaring, 104-105

anonymous functions, 107-108

this keyword, 105-107

disabling stylesheets, 209-211

displayData() function, 391

displaying

alert dialogs, 49

confirmation dialogs, 50

prompts, 50-51

division (/) operator, 26

do ... while loop, 91

doAjax() function, 276-277

document object, 12

cookie property, 156

getElementById() method, 51-52

reading properties of, 16

write() method, 14-15

Document Object Model. See DOM

$(document).ready handler, 318-319

documentation (JSON), 133

documents (HTML), including JavaScript in, 21-23

Dojo library, 305

DOM (Document Object Model), 10

animating DOM elements, 240-241

browser support for, 12

development of, 10

DOM Core, 199

DOM Inspector, 180-181

element attributes, editing, 191-192

explained, 11

JavaScript files, loading dynamically, 192-193

levels, 11

nodes

attributes property, 180

child nodes, 187-191

childNodes property, 174-175

creating, 185-187

determining whether nodes have child nodes, 182

explained, 171-173

firstChild property, 175

lastChild property, 176

names, 177

nextSibling property, 176

node lists, 174

nodeName property, 177

nodeValue property, 176-177

parentNode property, 176

previousSibling property, 176

types of, 173-174

values, 176-177

objects. See objects

DOM Core, 199

DOM Inspector, 180-181

domain attribute (cookies), 157-158

dot notation, 13

downloading

DOM Inspector, 180

jQuery, 317-319

drag and drop

in HTML5, 373-375

with jQuery UI, 337-340

drag() function, 375

draggable() method, 337-338

Dragonfly, 100

drawing with canvas element, 370-372

drop() function, 375

droppable() method, 339-340

dynamic menu creation, 193-197

dynamic file loading, 192-193

E

[top]

E constant, 61

E property (Math object), 407

ECMA (European Computer Manufacturers Association), 9

ECMAScript, 9

editing

dates/times, 58-59

element attributes, 191-192

editors

Geany, 400

jEdit, 400

Notepad++, 399

SciTE, 400

element nodes, 173

elements

<a>, 356

animating, 236-237, 322

animate() method, 324

sample program, 325-327

setInterval() method, 237, 246

setTimeout() method, 237, 246

sliding page elements, 323-324

transitions, 323

<article>, 366

<aside>, 366

attributes, editing, 191-192

<audio>, 369

<canvas>, 370-372

<embed>, 357

<figcaption>, 366

<figure>, 366

<footer>, 366

getting and setting content of, 320-321

<head>, 38-39

<header>, 366

<nav>, 366

<noscript>, 232

<object>, 357

reading attributes of, 179-180

<script>, 10-11, 21-22

<section>, 366

selecting, 319-320

by id, 51-52

with getElementsByTagName(), 177-179

showing/hiding, 321-322

<summary>, 366

<video>, 366-368

<embed> element, 357

enabling stylesheets, 209-211

encapsulation, 104, 115-116

ended attribute (<video> element), 367

enhancement, progressive, 222-223

equal sign (=), 27, 404

equality, testing for, 87-88

equality (==) operator, 405

error handling, 227-228. See also debugging, 94-96

escape() function, 156-157

escaping data, 41, 70-71, 156-157, 297

European Computer Manufacturers Association (ECMA), 9

eval() function, 123

event handlers, 30, 135

adding, 136-137, 148-151

advanced event handler registration

cross-browser implementation, 147-148

Microsoft method, 147

W3C method, 146-147

common event handlers, 136

cross-browser event handlers, 142-144, 147-148, 152

default actions, 138-141

inline event handlers, 136

jQuery, 328

onClick, 30-31, 144-145, 148-151

onMouseOut, 31-33

onMouseOver, 31-33

removing, 137, 148-151

event object

explained, 141

Microsoft approach, 142

W3C approach, 142

events

event handlers, 30, 135

adding, 136-137, 148-151

advanced event handler registration, 146-148

common event handlers, 136

cross-browser event handlers, 142-144, 147-148, 152

default actions, 138-141

inline event handlers, 136

jQuery, 328

onClick, 30-31, 144-145, 148-151

onMouseOut, 31-33

onMouseOver, 31-33

removing, 137, 148-151

event object

explained, 141

Microsoft approach, 142

W3C approach, 142

mouse events, capturing, 30

onClick, 30-31

onMouseOut, 31-33

onMouseOver, 31-33

properties, 143

events.js, 149-150

exclamation point (!), 403

exp method, 407

expires attribute (cookies), 158

exponential notation, 68

extending objects, 111-115

Extensible Markup Language (XML)

compared to JSON, 122

parsing, 285

extensions (browser). See browser extensions

F

[top]

$F() function, 307

F12 Developer Tools, 100

fadeIn() method, 323

fadeOut() method, 323

fadeTo() method, 323

fading

page elements, 323

between transparency and opacity, 238-239

Fahrenheit, converting Celsius to, 28-29

“falsy” values, 74

feature detection, 57, 116-118, 226-227

feedback for users, debugging, 293-294

figcaption element, 366

<figure> element, 366

File API (HTML5), 377-379

File interface, 377

FileList interface, 377

files. See also specific files

audio formats, 353-354

loading dynamically, 192-193

local files, interacting with, 377-379

naming, 219-220

video formats, 354-355

finding maximum and minimum, 60

Firebug, 100, 287-290, 299, 401

Firefox

DOM Inspector, 180-181

extensions, 395

Firebug, 100, 287-290, 299, 401

JavaScript support in, 384

firstChild property (DOM nodes), 175

Flash, 358-361

controlling with JavaScript, 359-361

methods, 359

flashLoaded() function, 359-361

Flickr, support for JSON, 122

floating-point numbers, 68

floor method, 407

floor() method, 59-60

.flv files, 355

footer element, 366

for loop, 91-92

for...in loop, 93

Form object, 308

forms

Form object, 308

sample Ajax form with jQuery, 330-332

forward slash (/), 26

forward() method, 53

fps (frames per second), 236

frame rate, 236, 242

frames per second (fps), 236

function operator, 38, 406

functions. See also methods

$(), 306-307

adding to page head, 38-39

Ajax callback functions, 264-265

allowDrop(), 375

animate(), 371

anonymous functions, 107-108

arc(), 371

arguments, 40-42

attachEvent(), 147

buttonReport(), 41-42

callback functions, 276

calling, 38

checkform(), 140

compared to methods, 38

constructor functions, 108-110

createCookie(), 159-162

creating, 37-38

cycle(), 98-99

deleteCookie(), 162-163

detachEvent, 147

displayData(), 391

doAjax(), 276-277

drag(), 375

drop(), 375

escape(), 156-157

eval(), 123

explained, 22, 37

$F(), 307

flashLoaded(), 359-361

getCookie(), 162-163

getElementArea(), 221

isFinite(), 70

jsonParse(), 125

lineTo(), 370

moveItRight(), 240-241

moveTo(), 370

naming, 38, 47

nesting, 47

outputting user messages with, 41-42

parse(), 123

parseFloat(), 69

parseInt(), 69

responseAjax(), 264-265

returning values from, 43

setInterval(), 97

showVars(), 45

syntax, 37-38

telltime(), 63, 228-230

toggleClass(), 208

Try.these, 308

unescape(), 156-157

variable scope, 44-46

G

[top]

games, animated shooting game, 242-245

Geany, 400

generating random numbers, 60-61

GET requests, 270, 275-276, 297

get() method, 329

getAllResponseHeaders() method, 258

getAttribute() method, 180, 191

getCookie() function, 162-163

getDate() method, 408

getDay() method, 408

getElementArea() function, 221

getElementById() method, 51-52, 117

getElements() method, 308

getElementsByTagName() method, 177-179

getFullYear() method, 65, 408

getHours() method, 408

getMilliseconds() method, 408

getMinutes() method, 408

getMonth() method, 408

getResponseHeader() method, 258

getSeconds() method, 408

getTime() method, 408

getTimezoneOffset() method, 65, 408

getUTCDate() method, 408

getUTCDay() method, 408

getUTCFullYear() method, 408

getUTCHours() method, 408

getUTCMilliseconds() method, 408

getUTCMinutes() method, 408

getUTCMonth() method, 408

getUTCSeconds() method, 408

getYear() method, 65

global objects, 14

global variables, 44-46

Google Ajax API CDN, 318

Google Apps Script, JavaScript support in, 384

Google Chrome extensions. See Chrome extensions, 383

GotoFrame() method, 359

graceful degradation, 221-222

graphics. See images

greater than (>) operator, 87, 405

greater than or equal to (>=) operator, 87, 405

H

[top]

handling

errors, 227-228

events. See event handlers

hasChildNodes() method, 182

<head> element, 38-39

<header> element, 366

Hello World example, 15-16

hexadecimal numbers, 68

hide() method, 322

hiding page elements, 321-322

history of jQuery, 333

history (browser), accessing, 52-53

history object, 12, 52-53

history of JavaScript, 9

HTML (HyperText Markup Language)

comment syntax, 23

elements. See elements

explained, 7

HTML5

<audio> element, 369

<canvas> element, 370-372

drag and drop, 373-375

File API, 377-379

learning, 380

local storage, 376-377

overview, 365-366

<video> element, 366-368

web site examples, 380

metatags, 280

white space in, 175-176

html() method, 320, 390

HTML5

<audio> element, 369

<canvas> element, 370-372

drag and drop, 373-375

File API, 377-379

learning, 380

local storage, 376-377

overview, 365-366

<video> element, 366-368

website examples, 380

HTTP

GET requests, 275-276, 297

POST requests, 275-276

HyperText Markup Language. See HTML

hyphen (-), 26

I

[top]

icon files for Google Chrome extensions, 388

IDs, selecting elements by, 51-52

if() statement, 85-86

testing for equality, 87-88

testing multiple conditions, 88

image rollovers, creating, 32-33

images

animation

animated shooting game example, 242-245

CSS3 transitions and transformations, 239-240, 246

DOM elements, 240-241

frame rate, 236, 242

page elements, 236-237, 246

performance optimization, 242

timers, 242

transparency, 238-239

cycling on web page, 97-100

drawing with canvas element, 370-372

preloading, 235-236

rollovers, creating, 32-33

in operator, 406

inappropriate use of Ajax, 295-296

including

jQuery from CDNs (Content Delivery Networks), 318

jQuery UI in web pages, 336-337

increment (++) operator, 26

indexOf() method, 71-72, 75-76, 406

infinity, 69-70

inheritance, 104, 112-113

initializing arrays, 75

inline event handlers, 136

innerHTML property, 52, 199

insertBefore() method, 188

inserting child nodes, 188

instanceof operator, 406

instantiating objects, 108-110, 256-258

integers, 67-68

interacting with user

alert dialogs, 49

confirmation dialogs, 50

prompts, 50-51

Internet Explorer, 9

debugging Ajax with, 290-292

F12 Developer Tools, 100

interpreted languages, 10

isFinite() function, 70

IsPlaying() method, 359

J

[top]

Java, 8

JavaScript Object Notation. See JSON

jEdit, 400

join() method, 75-76

jQuery, 306

command chaining, 324

compatibility with other libraries, 333

development of, 333

$(document).ready handler, 318-319

downloading, 317-318

event handling, 328

implementing Ajax with, 328

ajax() method, 330

get() method, 329

load() method, 329

post() method, 330

sample Ajax form with jQuery, 330-332

including from CDNs (Content Delivery Networks), 318

jQuery CDN, 318

jQuery UI

accordian widget, 343-344

advantages of, 335-336

customized widgets, 349

date picker widget, 344-346

drag and drop, 337-340

including in web pages, 336-337

resizing handles, 341

sortable lists, 341-342

tabbed interfaces, 346-348

ThemeRoller, 336-337

methods

ajax(), 330

attr(), 321

get(), 329

hide(), 322

html(), 320

load(), 329

post(), 330

show(), 321-322

text(), 320-321

toggle(), 322

page elements

animating, 322-327

getting and setting content of, 320-321

selecting, 319-320

showing/hiding, 321-322

jQuery CDN, 318

.js file extension, 22

jScript, 9

JSLint, 401

JSON (JavaScript Object Notation), 121

accessing JSON data, 123-124

with eval() function, 123

with native browser support, 123

with parse() function, 123

associative arrays, simulating, 127

compared to XML, 122

data serialization, 124-126

data types, 126

documentation, 133

explained, 121

Flickr support for, 122

objects, creating, 127

arrays, 128-129

methods, 128

multilevel objects, 129-131

objects within objects, 129

properties, 128

parsing, 125-126

security, 131

syntax, 121-122

web page, 121

jsonParse() function, 125

junctions, 90

K

[top]

keyCode property (events), 143

keyword META information, returning from remote sites, 280-283

keywords. See functions; methods; statements

L

[top]

language attribute (<script> element), 10

lastChild property (DOM nodes), 176

lastIndexOf() method, 71-72, 75-77, 406

layers

behavior layer, 223

presentation layer, 223

semantic layer, 223

leaving loops

with break, 92-93

with continue, 101

left shift (>>) operator, 404

length property

arrays, 75

history object, 52

less than (<) operator, 87, 405

less than or equal to (<=) operator, 87, 405

libraries, 303

advantages of, 303-304

Ajax library

callback function, 276

goals, 274

HTTP GET and POST requests, 275-276

including in HTML page, 278-280

making Ajax calls, 276-277

myAjaxLib.js source code, 277-278

overview, 273

returning keyword META information from remote sites, 280-283

XMLHttpRequest instances, 274-275

Dojo, 305

including in web pages, 314

jQuery. See jQuery

MooTools, 305

Prototype Framework, 305

prototype.js

$() function, 306-307

Ajax.PeriodicalUpdater class, 310-311

Ajax.Request class, 309

Ajax.Updater class, 309-310

$F() function, 307

Form object, 308

stock price reader, 311-312

Try.these() function, 308

Yahoo! UI Library, 305

LibreOffice.org, JavaScript support in, 383

lineTo() function, 370

links, debugging, 293

lists, sorting, 341-342

LN2, 61, 407

LN10, 61, 407

load() method, 329

loading

JavaScript files dynamically, 192-193

multimedia

with <a> element, 356

with <embed> element, 357

with <object> element, 357

with plug-ins, 357-358

local files, interacting with, 377-379

local storage with HTML5, 376-377

local variables, 44-46

localStorage object, 376

location object

navigating with, 54

properties, 53

reloading pages, 54

log method, 407

LOG10E, 61, 407

LOG2E, 61, 407

logical AND (&&) operator, 89

logical operators, 89-90, 403

logical OR (||) operator, 89

loop attribute (<video> element), 367

loops, 90. See also statements

choosing, 101

do ... while, 91

for, 91-92

for...in, 93

leaving with break, 92-93

leaving with continue, 101

while, 90-91

loosely typed languages, 67

lowercase, converting strings to, 73

M

[top]

manifest.json file, 388-389

Math object, 59

constants, 407

finding maximum and minimum, 60

generating random numbers, 60-61

mathematical constants, 61

methods, 59-61, 407

rounding, 60

with keyword, 61-62

mathematical constants, 61

max() method, 60, 407

maximum numbers, finding, 60

menu.js, 196-197

menus, creating dynamically, 193-197

messages, outputting with functions, 41-42

META information, returning from remote sites, 280-283

metatags, 280

metatags.html, 282

methods, 12. See also functions

abort(), 258

accordion(), 343-344

addEventListener, 146

adding with prototype, 111-112

ajax(), 330

alert(), 49

animate(), 324

appendChild(), 187-188

attr(), 321

back(), 53

canPlayType(), 368

ceil(), 59-60

clearRect(), 371

cloneNode(), 186-187

compared to functions, 38

concat(), 71-72, 75-76

confirm(), 50

createElement(), 185-186

createElementTextNode(), 186

datepicker(), 345-346

defining with JSON (JavaScript Object Notation), 128

draggable(), 337-338

droppable(), 339-340

fadeIn(), 323

fadeOut(), 323

fadeTo(), 323

flashLoaded(), 359

floor(), 59-60

forward(), 53

get(), 329

getAllResponseHeaders(), 258

getAttribute(), 180, 191

getElementById(), 51-52, 117

getElements(), 308

getElementsByTagName(), 177-179

getFullYear(), 65

getResponseHeader(), 258

getTimezoneOffset(), 65

getYear(), 65

GotoFrame(), 359

hasChildNodes(), 182

hide(), 322

html(), 320, 390

indexOf(), 71-72, 75-76

insertBefore(), 188

IsPlaying(), 359

join(), 75-76

lastIndexOf(), 71-72, 75-77

load(), 329

max(), 59-60

min(), 59-60

naming, 219-220

open(), 259

pause(), 368

PercentLoaded(), 359

Play(), 359, 368

post(), 330

prompt(), 50-51

random(), 59-60

reload, 54

reload(), 54

removeEventListener, 146

replace(), 71-72

resizable(), 341

Rewind(), 359

round(), 59-60

send(), 258-260

serialize(), 308

setAttribute(), 191

setFullYear(), 65

setInterval(), 237, 246, 371

setRequestHeader(), 258

setTimeout(), 237, 246

setYear(), 65

show(), 321-322

slice(), 75-77

slideDown(), 323

slideUp(), 323

sort(), 76-77

sortable(), 341-342

splice(), 76-77

split(), 71-73

StopPlay(), 359

stringify(), 124

substr(), 72-73

tabs(), 347

text(), 320-321

toDateString(), 59

toggle(), 322

toLowerCase(), 72-73

toString(), 75-76

TotalFrames(), 359

toTimeString(), 59

toUpperCase(), 72-73

Zoom(), 359

Microsoft CDN, 318

min() method, 59-60, 407

minimum numbers, finding, 60

modulus (%) operator, 26, 403

monitoring server status, 263

readyState property, 263

server response status codes, 264

MooTools library, 305

mouse cursor, changing, 215

mouse events, capturing

onClick event handler, 30-31

onMouseOut event handler, 31-33

onMouseOver event handler, 31-33

.mov files, 354

moveItRight() function, 240-241

moveTo() function, 370

movies. See video

moving ball animation, 370-372

Mozilla Firefox

DOM Inspector, 180-181

extensions, 395

Firebug, 100, 287-290, 299, 401

JavaScript support in, 384

.mp3 files, 354

.mp4 files, 355

.mpeg files, 354

.mpg files, 354

multilevel objects (JSON), 129-131

multiline comments, 24

multimedia

audio

formats, 353-354

playing with <audio> element, 369

streaming, 363

browser plug-ins, 355-358

disadvantages of, 363

Flash, 358-361

controlling with JavaScript, 359-361

methods, 359

loading and playing

with <a> element, 356

with <embed> element, 357

with <object> element, 357

video

formats, 354-355

playing with <video> element, 366-368

multiple arguments, 40-42

multiple conditions, testing for, 88

multiple platforms, testing across, 296

multiple values, setting in cookies, 165-166

multiplication (*) operator, 26

myAjaxLib

callback function, 276

goals, 274

HTTP GET and POST requests, 275-276

including in HTML page, 278-280

making Ajax calls, 276-277

myAjaxLib.js source code, 277-278

overview, 273

returning keyword META information from remote sites, 280-283

XMLHttpRequest instances, 274-275

N

[top]

\n (new line) character, 41

naming conventions, 219-220

files, 219-220

functions, 38, 47

methods, 219-220

nodes, 177

properties, 219-220

variables, 25

NaN (not a number), 69

natural numbers, 67

<nav> element, 366

navigating

DOM (Document Object Model). See DOM (Document Object Model), 171

with location object, 54

navigator object, 54-57

navigator.html file, 55

negation operator (!), 74

negative infinity, 70

nesting functions, 47

Netscape Navigator 4, 9

new line (\n) character, 41

new operator, 406

nextSibling property (DOM nodes), 176

Node js, 395

NodeList, 174

nodeName property (DOM nodes), 177

nodes (DOM)

child nodes

appending, 187-188

inserting, 188

removing, 191

replacing, 188-190

creating

cloneNode() method, 186-187

createElement() method, 185-186

createElementTextNode() method, 186

determining whether nodes have child nodes, 182

explained, 171-173

names, 177

node lists, 174

properties

attributes, 180

childNodes, 174-175

firstChild, 175

lastChild, 176

nextSibling, 176

nodeName, 177

nodeValue, 176-177

parentNode, 176

previousSibling, 176

types of, 173-174

values, 176-177

nodeValue property (DOM nodes), 176-177

<noscript> element, 232

not a number (NaN), 69

not equal (!=) operator, 405

NOT operators

! (logical NOT), 403

~ (bitwise NOT), 404

Notepad++, 399

null values, 51, 74

numbers, 67

converting strings to, 69

finding maximum and minimum, 60

floating-point numbers, 68

hexadecimal numbers, 68

infinity, 69-70

integers, 67-68

NaN (not a number), 69

natural numbers, 67

random numbers, generating, 60-61

rounding, 60

whole numbers, 67

O

[top]

object literals, 74

Object object, 104-105

Object Oriented languages, 104

<object> element, 357

object-oriented programming. See OOP

objects. See also OOP (object-oriented programming)

bookListObject, 129-131

creating direct instances of, 104-105

anonymous functions, 107-108

this keyword, 105-107

creating with constructor functions, 108-110

creating with JSON, 127

arrays, 128-129

methods, 128

multilevel objects, 129-131

objects within objects, 129

properties, 128

Date, 57

creating with a given date and time, 58

creating with current date and time, 57

methods, 408-410

reading date and time, 62-64

setting/editing dates and times, 58-59

time zones, 65

document, 12

cookie property, 156

getElementById() method, 51-52

reading properties of, 16

write() method, 14-15

encapsulation, 115-116

event

explained, 141

Microsoft approach, 142

W3C approach, 142

explained, 12

extending, 111-115

feature detection, 116-118

Form, 308

global objects, 14

history, 12, 52-53

inheritance, 112-113

instantiating, 108-110

JSON (JavaScript Object Notation), 13

accessing JSON data, 123-124

associative arrays, simulating, 127

compared to XML, 122

data serialization, 124-126

data types, 126

explained, 121

Flickr support for, 122

multilevel objects, 129-131

object creation, 127-129

parsing, 125-126

syntax, 121-122

web page, 121

localStorage, 376

location, 53-54

navigating with, 54

properties, 53

reloading pages, 54

Math

constants, 407

finding maximum and minimum, 60

generating random numbers, 60-61

mathematical constants, 61

methods, 59-61, 407

rounding, 60

with keyword, 61-62

navigator, 54-57

Object, 104-105

portability, 119

sessionStorage, 376

styleSheets, 209

window, 12-13

alert() method, 14, 49

confirm() method, 50

prompt() method, 50-51

XMLHttpRequest

creating instances of, 256-258

methods, 258-260

overview, 253-256

properties, 258-259

obtrusive code, converting into unobtrusive code, 228-231

onBlur event handler, 136

onChange event handler, 136

onClick event handler, 30-31, 136

adding/removing, 148-151

listing onClick event properties, 144-145

properties, listing, 144

onDblClick event handler, 136

onFocus event handler, 136

onKeydown event handler, 136

onKeypress event handler, 136

onKeyup event handler, 136

onLoad event handler, 136

onMousedown event handler, 136

onMousemove event handler, 136

onMouseOut event handler, 31-33, 136

onMouseOver event handler, 31-33, 136

onMouseup event handler, 136

onreadystatechange property (XMLHttpRequest object), 258

onReset event handler, 136

onSelect event handler, 136

onSubmit event handler, 136, 139-140

onUnload event handler, 136

OOP (object-oriented programming)

advantages of, 104

encapsulation, 115-116

feature detection, 116-118

inheritance, 112-113

object creation

constructor functions, 108-110

direct instances, 105-108

object extension, 114-115

overview, 103-104

when to use, 119

opacity, fading between transparency and opacity, 238-239

open() method, 259

opening DOM Inspector, 180

OpenOffice.org, JavaScript support in, 383

Opera Dragonfly, 100

operators

arithmetic operators, 26-27, 403

assignment operators, 404-405

bitwise operators, 404

comparison operators, 86-87, 405

concatenation operator, 27-28

logical operators, 89-90, 403

negation (!) operator, 74

precedence, 27

special operators, 406

string operators, 403

typeof, 117-118, 226

optimizing performance. See performance considerations, 18, 24, 242

OR operators

| (bitwise OR), 404

|| (logical OR), 89, 403

overuse of JavaScript, avoiding, 217-218

P

[top]

packing extensions, 393

page elements. See elements

page head, adding functions to, 38-39

parentNode property (DOM nodes), 176

parse() method, 123, 408

parseFloat() function, 69

parseInt() function, 69

parsing

JSON strings, 125-126

text, 285

XML, 285

path attribute (cookies), 158

pause() method, 368

paused attribute (<video> element), 367

PDF files, JavaScript support in, 383

percent sign (%), 26

PercentLoaded() method, 359

performance considerations

animation, 242

comments, 24

JavaScript, 18

Permission Denied errors, 297

PHP-enabled web servers, 282

PI, 61, 407

placing style declarations, 204

Play() method, 359, 368

playing multimedia

with <audio> element, 369

with <a> element, 356

with <embed> element, 357

with <object> element, 357

with plug-ins, 357-358

with <video> element, 366-368

plug-ins (browser), 355-358

plus sign (+), 403

pop-up information, 295

popup.html Google Chrome extension

basic popup.html file, 389-391

complete popup.html file, 391-392

icon files, 388

manifest.json file, 388-389

returning airport information, 387-388

writing, 384-386

POST requests, 270, 275-276

post() method, 330

poster attribute (<video> element), 367

pow method, 407

precedence of operators, 27

preloading images, 235-236

presentation layer, 223

preventing default actions, 138-141

previousSibling property (DOM nodes), 176

procedural programming, 103

programs, 21

Ajax clock application, 267-269

banner cycling script, 97-100

debugging, 94-96

definition of, 8

Hello World example, 15-16

including in web pages, 21-23

stock price reader, 311-312

progressive enhancement, 222-223

prompt() method, 50-51

prompts, displaying, 50-51

properties. See also specific properties

defining with JSON (JavaScript Object Notation), 128

explained, 12

naming, 219-220

reading, 16

stringlike properties, 156

style properties, 205-206

protocols, stateless, 155

Prototype Framework library, 305

prototype keyword, extending objects with, 111-115

prototype.js library

$() function, 306-307

Ajax.PeriodicalUpdater class, 310-311

Ajax.Request class, 309

Ajax.Updater class, 309-310

$F() function, 307

Form object, 308

stock price reader, 311-312

Try.these function, 308

Q-R

[top]

QuickTime files, 354

.ram files, 354

random method, 408

random numbers, generating, 60-61

random() method, 59-60

reading

cookies, 161-162

date and time, 62-64

document object properties, 16

element attributes, 179-180

readystate property (XMLHttpRequest object), 258, 263-264

Real Audio files, 354

RealVideo files, 354

reload() method, 54

reloading web pages, 54

remote sites, returning keyword META information from, 280-283

removeEventListen method, 146

removing

child nodes, 191

event handlers, 137, 148-151

rendering context, 370

replace() method, 71-72, 406

replacing

child nodes, 188-190

substrings within strings, 72

requests

Ajax server requests

dealing with browser cache, 261-262

overview, 253-254

sending, 260-261

HTTP GET and POST requests, 270, 275-276, 297

XMLHttpRequest

creating instances of, 256-258

methods, 258-260

overview, 256

properties, 258-259

Resig, John, 333

resizable() method, 341

resizing handles, adding, 341

responding to events. See event handlers

responseAjax() function, 264-265

responses (server), 254

responseText property (XMLHttpRequest object), 258, 265-266, 285

responseXML property (XMLHttpRequest object), 258, 265-267

return values, 43

reusing code, 104, 220-221

Rewind() method, 359

right shift (<<) operator, 404

.rm files, 354

round() method, 59-60, 407

rounding numbers, 60

S

[top]

SciTE, 400

scope of variables, 44-46

screenX property (events), 143

screenY property (events), 143

<script> element, 10-11, 21-22

scripts. See programs

search engine spiders, 294, 299

<section> element, 366

secure attribute (cookies), 158

security

Ajax, 296

cookies, 166

JSON, 131

selecting

elements, 319-320

by id, 51-52

with getElementsByTagName(), 177-179

stylesheets, 211-214

semantic layer, 223

send() method, 258-260

sending Ajax server requests, 260-261

serialization with JSON (JavaScript Object Notation), 124-126

serialize() method, 308

server requests (Ajax)

dealing with browser cache, 261-262

overview, 253-254

sending, 260-261

server responses, 254

server status, monitoring, 263

readyState property, 263

server response status codes, 264

server-side programming, 8

sessionStorage object, 376

setAttribute() method, 191

setDate() method, 408

setFullYear() method, 65, 409

setHours() method, 409

setInterval() method, 97, 237, 246, 371

setMilliseconds() method, 409

setMinutes() method, 409

setMonth() method, 409

setRequestHeader() method, 258

setSeconds() method, 409

setTime() method, 409

setTimeout() method, 237, 246

setting

dates/times, 58-59

page element content, 320-321

setUTCDate() method, 409

setUTCFullYear() method, 409

setUTCHours() method, 409

setUTCMilliseconds() method, 409

setUTCMinutes() method, 409

setUTCMonth() method, 409

setUTCSeconds() method, 409

setYear() method, 65

shiftKey property (events), 143

ShockWave Flash. See Flash, 358-361

shooting game (animated), 242-245

show() method, 321-322

showVars() function, 45

simulating associative arrays, 127

sin method, 407

slash (/), 403

slice() method, 75-77

slicing arrays, 77

slideDown() method, 323

slideUp() method, 323

sliding page elements, 323-324

software. See tools, 399-401

sort() method, 76-77

sortable() method, 341-342

sorting

arrays, 77

lists, 341-342

sound

formats, 353-354

playing with audio element, 369

streaming, 363

special operators, 406

Sphere, JavaScript support in, 384

spiders, 294, 299

splice() method, 76-77

splicing arrays, 77

split method, 406

split() method, 71-73

splitting strings, 73

sqrt method, 407

SQRT1_2, 61, 407

SQRT2, 61, 407

stateless protocols, 155

statements. See also loops

break, 92-93

catch, 227-228

comments, 24

continue, 101

do ... while, 91

explained, 23

for, 91-92

for...in, 93

if(), 85-86

testing for equality, 87-88

testing multiple conditions, 88

function, 38

null, 74

prototype, 111-115

switch, 88-89

this, 105-107

try, 227-228

while, 90-91

with, 61-62

static web pages, 7

status of server, monitoring

readyState property, 263

server response status codes, 264

status property (XMLHttpRequest object), 258

statusText property (XMLHttpRequest object), 258

stock price reader program, 311-312

StopPlay() method, 359

storage, local storage with HTML5, 376-377

streaming audio/video, 363

strict equality (===) operator, 405

strict not-equal-to (!==) operator, 405

stringify() method, 124

stringlike properties, 156

strings

assigning to variable values, 25

Boolean values, 73-74

concatenating, 27-28, 72

converting

to numbers, 69

to uppercase/lowercase, 73

definition of, 70

escape sequences, 70-71

extending, 114

JSON strings

creating, 124

deserializing, 123, 133

parsing, 125-126

maximum length of, 80

methods, 71-72, 406

concat(), 71-72

indexOf(), 71-72

lastIndexOf(), 71-72

replace(), 71-72

split(), 71-73

substr(), 72-73

toLowerCase(), 72-73

toUpperCase(), 72-73

operators, 403

replacing substrings in, 72

splitting, 73

style property (DOM), 204-207

styles (CSS)

advantages of, 201-202

DOM style property, 204-207

style declarations

placing, 204

syntax, 202-203

style properties, setting, 205-206

stylesheets

DOM styleSheets object, 209

enabling/disabling, 209-211

selecting, 211-214

switching, 209-211

stylesheets

DOM styleSheets object, 209

enabling/disabling, 209-211

selecting, 211-214

switching, 209-211

substr() method, 72-73

substring method, 406

subtraction (-) operator, 26

<summary> element, 366

supporting users with JavaScript disabled, 232

.swf files, 355, 358

switch statement, 88-89

switching stylesheets, 209-211

T

[top]

tabbed interfaces, 346-348

tabs widget, 346-348

tabs() method, 347

tags. See elements

tan method, 407

telltime() function, 63, 228-230

temperature.html, 29

testing

Ajax across multiple platforms, 296

cookies

cookies.js, 162-163

cookietest.html, 163-165

cookietest2.html, 164-165

for equality, 87-88

in multiple browsers, 18

multiple conditions, 88

text nodes, 173

text parsing, 285

text() method, 320-321

ThemeRoller, 336-337

this keyword, 105-107

time

reading date and time, 62-64

setting/editing, 58-59

time zones, 65

timers, 242

title, selecting stylesheets by, 213-214

toDateString() method, 59, 409

toggle() method, 322

toggleClass() function, 208

toggling between stylesheets, 210-211

toLocaleDateString() method, 409

toLocaleString() method, 409

toLocaleTimeString() method, 409

toLowerCase method, 406

tools

Firebug, 401

jEdit, 400

JSLint, 401

Geany, 400

Notepad++, 399

SciTE, 400

WDG (Web Design Group) validation service, 401

toString() method, 75-76, 409

TotalFrames() method, 359

toTimeString() method, 59, 409

toUpperCase() method, 72-73, 406

toUTCString() method, 409

transformations, animating, 239-240, 246

transitions, animating, 239-240, 246, 323

transparency, animating, 238-239

try statement, 227-228

Try.these function, 308

turning off JavaScript, 232

type attribute

events, 143

<script> element, 10

typeof operator, 117-118, 226, 406

U

[top]

undefined values, 74

unescape() function, 156-157

unescaping data, 156-157

Universal Time (UTC), 65

unobtrusive JavaScript

converting code into, 228-231

explained, 223-226

uppercase, converting strings to, 73

user interaction

alert dialogs, 49

confirmation dialogs, 50

prompts, 50-51

user messages, outputting with functions, 41-42

users with JavaScript disabled, supporting, 232

UTC (Universal Time), 65

UTC() method, 410

V

[top]

validators, 400-401

valueOf() method, 410

values

assigning to variables, 25

Boolean values, 73-74

cookie values

cookieName, 157

cookieValue, 157

multiple values, 165-166

node values, 176-177

null values, 51, 74

returning from functions, 43

undefined values, 74

variables

assigning values to, 25

explained, 24-25

naming, 25

scope, 44-46

undefined, 74

VBScript, 9

video

browser plug-ins, 355-358

formats, 354-355

loading and playing

with <a> element, 356

with <embed> element, 357

with <object> element, 357

with <video> element, 366-368

streaming, 363

<video> element, 366-368

void operator, 406

volume attribute (<video> element), 367

W

[top]

W3C (World Wide Web Consortium), 10, 401

.wav files, 354

WDG (Web Design Group) validation service, 401

web browsers. See browsers

web pages

banner cycling script, 97-100

drawing on, 370-372

including Ajax library in, 278-280

including JavaScript in, 21-23

including jQuery UI in, 336-337

including libraries in, 314

menus, creating on-the-fly, 193-197

navigating with location object, 54

reloading, 54

static pages, 7

web servers, PHP-enabled, 282

WebM, 367

while loop, 90-91

whitespace, 34, 175-176

whole numbers, 67

widgets

accordian, 343-344

customized widgets, 349

date picker, 344-346

tabs, 346-348

window object, 12-13

alert() method, 14, 49

confirm() method, 50

prompt() method, 50-51

with keyword, 61-62

.wma files, 354

.wmv files, 354

World Wide Web Consortium (W3C), 10, 401

write() method, 14-15

writing

comments, 218-219

cookies, 158-161

Google Chrome extensions, 384-386

X

[top]

XAMPP, 282

XHTML, 31

XML (Extensible Markup Language)

compared to JSON, 122

parsing, 285

XMLHttpRequest object

creating instances of, 256-258, 274-275

methods, 258-259

open(), 259

send(), 259-260

overview, 253-256

properties, 258-259

responseText, 265-266

responseXML, 265-267

XOR operators (^), 404

Y-Z

[top]

Yahoo! UI Library, 305

zero fill right shift (>>>) operator, 404

Zoom() method, 359