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.

312<br />

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

Example<br />

A majority of examples for other TextRange object methods in this chapter use<br />

the moveToElementText() method. Listings 19-10 and 19-11 earlier in this chapter<br />

show the method within an application context.<br />

moveToPoint(x, y)<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

Use The Evaluator to see the moveToPoint() method in action. Begin by creating<br />

a text range for the entire BODY element:<br />

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

Now, invoke the moveToPoint() method to a location 100, 100, which turns out to<br />

be in the rectangle space of the Results textarea:<br />

a.moveToPoint(100,100)<br />

If you type a into the bottom text box and view the properties, both the<br />

htmlText and text properties are empty because the insertion point represents no<br />

visible text content. But if you gradually move, for example, the start point backward<br />

one character at a time, you will see the htmlText and text properties begin<br />

to fill in with the body text that comes before the TEXTAREA element, namely the<br />

“Results:” label and the tag between it and the TEXTAREA element. Enter the<br />

following statement into the top text box and click the Evaluate button several<br />

times.<br />

a.moveStart(“character”, -1)<br />

Enter a into the bottom text box after each evaluation to list the properties of the<br />

range.<br />

parentElement()<br />

TextRange.parentElement()<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 experiment with the<br />

parentElement() method. Begin by setting the text range to the myEM element:<br />

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

a.moveToElementText(myEM)

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

Saved successfully!

Ooh no, something went wrong!