User Selection and Editing Operations
This chapter introduces the TextRange object, which is used to access and manipulate the document's contents. Microsoft Internet Explorer 4.0 and Dynamic HTML are built over an editing engine. Dynamic HTML defines an object model that can manipulate a document through script, similar to a text editor. The TextRange object represents the editing capabilities of the browser and exposes operations that constitute the editing model. Using the TextRange object, you can edit any text and you can access and manipulate the highlighted text that the user has selected on the screen.
The following topics are covered in this chapter:
- Introducing the TextRange object
The TextRange object exposes the document's contents in text format similar to an editing tool. This section introduces the TextRange object, how it represents the text contents of the document, and its relationship to the document's structure. In addition, some of the limitations and ambiguities of the TextRange object are discussed.
- Programming the TextRange object
This section shows you how to navigate and modify a document's contents using the TextRange object's properties and methods.
- Accessing the user's selection
This section shows you how to access the user's selection, one of the primary uses of the TextRange object. Both plain text and HTML text selected by the user are accessible, and the user's current selection can be manipulated and changed.
- Executing commands
Dynamic HTML exposes a set of editing-related methods that are exposed both on the document and on the TextRange object. This section shows you how to use these methods to query for information about the document and to manipulate the appearance of the document. The methods that manipulate the document are used to indirectly modify the HTML in order to obtain desired effects-for example, to create an Anchor element from arbitrary text.