Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. EditContext
  4. EditContext()

EditContext: EditContext() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

TheEditContext() constructor returns a newEditContext object.

Syntax

js
new EditContext()new EditContext(options)

Parameters

optionsOptional

An optional object with the following properties:

text

A string to set the initial text of theEditContext.

selectionStart

A number to set the initial selection start of theEditContext.

selectionEnd

A number to set the initial selection end of theEditContext.

Examples

Instantiating anEditContext object

The following example creates a newEditContext object with the initial text "Hello world!" and the initial selection covering the entire text.

html
<div></div>
js
const initialText = "Hello world!";const editContext = new EditContext({  text: initialText,  selectionStart: 0,  selectionEnd: initialText.length,});const editorElement = document.getElementById("editor");editorElement.editContext = editContext;console.log(  `EditContext object ready. Text: ${editContext.text}. Selection: ${editContext.selectionStart} - ${editContext.selectionEnd}.`,);

Specifications

Specification
EditContext API
# dom-editcontext-constructor

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp