15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

314<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

select()<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

See Listing 19-11 earlier in this chapter for an example of the select() method<br />

in use.<br />

setEndPoint(“type”, otherRangeRef)<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

Use The Evaluator to experiment with the setEndPoint() method. Begin by creating<br />

two independent text ranges, one for the myP element and one for myEM:<br />

a = document.body.createTextRange()<br />

a.moveToElementText(myP)<br />

b = document.body.createTextRange()<br />

b.moveToElementText(myEM)<br />

Before moving any end points, compare the HTML for each of those ranges:<br />

a.htmlText<br />

b.htmlText<br />

Now, move the start point of the a text range to the end point of the b text range:<br />

a.setEndPoint(“StartToEnd”, b)<br />

If you now view the HTML for the a range,<br />

a.htmlText<br />

TextRange.setEndPoint()<br />

you see that the tag of the original a text range is nowhere to be found. This<br />

demonstration is a good lesson to use the setEndPoint() method primarily if you<br />

are concerned only with visible body text being inside ranges, rather than an element<br />

with its tags.

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

Saved successfully!

Ooh no, something went wrong!