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.

Chapter 5 ✦ Body Text Objects (Chapter 19)<br />

<br />

<br />

<br />

NN6 Selection Object Replacement<br />

<br />

This paragraph<br />

contains text that you can select. Selections are deleted and<br />

replaced by all uppercase versions of the selected text.<br />

Undo Last<br />

Start Over<br />

<br />

<br />

isValidFragment(“HTMLText”)<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓<br />

Example<br />

You can try the validity of any strings that you like in The Evaluator (Chapter 13<br />

in the <strong>JavaScript</strong> <strong>Bible</strong>). You will discover, however, that the object model can make<br />

a document fragment out of just about any string. For instance, if you attempt to<br />

create a document fragment out of some random text and an end tag, the document<br />

fragment will consist of a text node and an element node of the type indicated by<br />

the end tag.<br />

selectNode(nodeReference)<br />

selectNodeContents(nodeReference)<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to see the behavior of<br />

both the selectNode() and selectNodeContents() methods work. Begin by creating<br />

a new range object.<br />

a = document.createRange()<br />

Set the range boundaries to include the myP element node:<br />

a.selectNode(document.getElementById(“myP”))<br />

287<br />

Range.selectNode()

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

Saved successfully!

Ooh no, something went wrong!