• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Creating Text Ranges

To create a text range, you can use the <BODY> element’s createTextRange method (see Table 9.12). After you have a text range, several methods (as you can see in Table 11.15 such as move, moveStart, moveEnd, moveToElementText, expand, and so on) enable you to position the text range as you want it.

Here’s an example we’ve already seen in Chapter 5—it’s Listing 05-15.html on the web site. In this case, I create a text range, move it to enclose an element’s text, and then use the text range’s pasteHTML method to replace the text in the range, all when the user clicks a button:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint