15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Body Text<br />

Objects<br />

(Chapter 19)<br />

The subject of body text objects encompasses both HTML<br />

element objects and several abstract DOM objects that<br />

make it easier for scripts to manipulate text-oriented body<br />

content that may not be contained within its own element tag.<br />

While the HTML element objects are easy to grasp, the<br />

abstract objects that work with stretches of visible body text<br />

have their own vocabularies and peculiarities.<br />

Many HTML element objects in this category may become<br />

obsolete when the installed base of browsers capable of supporting<br />

Cascading Style Sheets reaches critical mass. CSS<br />

adherents would much rather use style sheets for font specifications<br />

in place of the old-fashioned tag. But other<br />

elements in this group, such as the header elements (H1, H2,<br />

and so on), provide context for content that scripts may find<br />

useful for tasks such as creating a table of contents on the fly.<br />

More intriguing is the concept of a text range, which is<br />

essentially an object that represents an arbitrary series of text<br />

characters within a document. A text ranges can work within<br />

an element (or text node) or extend beyond element borders,<br />

just as if a user selected a bunch of text that includes portions<br />

of what are HTML elements behind the scenes.<br />

Unfortunately for scripters, the vocabulary for text range<br />

manipulation is very different for the IE4+/Windows and W3C<br />

object models. Moreover, the two objects do not always share<br />

the same functionality, making it even more difficult to program<br />

cross-browser implementations using text ranges. Be<br />

alert to the compatibility ratings for each example before trying<br />

out a listing or step-by-step sequence.<br />

5<br />

C H A P T E R<br />

✦ ✦ ✦ ✦<br />

In This Chapter<br />

Using the NN Range<br />

and IE TextRange<br />

objects<br />

Working with text<br />

selections<br />

Scripting search and<br />

replace actions<br />

✦ ✦ ✦ ✦

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!