Skip to Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
you’re on your way
233
the document object model
Sweet! Now I can nd any element I want, move up
and down the DOM tree... I’ll bet I can get element
names and text values, too, right?
Remember, everything in a DOM tree is a node.
Elements and text are special kinds of nodes, but
they’re still nodes. Anytime you have a node, you
can get the name of the node with nodeName,
and the value of the node with nodeValue.
You’ve got to be careful what type of node you’re
working on, though, or you could end up getting
a null value when you’re expecting the name
of an element or a string of text. An element
node has a name, like “div” or “img”, but won’t
have a value. And a text node won’t have a
name, but it will have a value: the actual text
stored in the node.
Let’s take a look and see how this works:
The node knows... pretty much everything.
“breadth-rst”
em
div
nodeName
nodeValue
“div”
null/undened
“breadth-rst”
The nodeValue for an
element node is undened.
The nodeValue
of a text node
is its text.
Element nodes all
have a nodeName.
Text nodes do not
have a nodeName.
node type
node
element
node
“em”
null/undened
element
node
null/undenedtext node
234
Chapter 4
You’ve got to keep up with what type of node you’re working on, and always know where
in the DOM tree your variables are pointing. To help you get ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content