[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/API/HTMLInputElement/setSelectionRange [Back]  [Original]

HTMLInputElement: setSelectionRange() method - Web API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

HTMLInputElement: setSelectionRange() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

HTMLInputElement.setSelectionRange() <input> <textarea> .

, . . .

HTMLInputElement.selectionStart, selectionEnd selectionDirection .

WHATWG forms spec selectionStart, selectionEnd setSelectionRange , , URL, . Chrome 33 . , "HTMLInputElement 'selectionStart' : ('number')() " .

HTMLInputElement.select() .

In this article

js
setSelectionRange(selectionStart, selectionEnd)
setSelectionRange(selectionStart, selectionEnd, selectionDirection)

selectionEnd selectionStart , selectionEnd .

selectionStart

0 . .

selectionEnd

0 . .

selectionDirection Optional

. :

  • "forward"
  • "backward"
  • "none" . .

(undefined).

, ("Mozilla" "zil") .

HTML

html
<input type="text" id="text-box" size="20" value="Mozilla" />
<button >Select text</button>

JavaScript

js
function selectText() {
  const input = document.getElementById("text-box");
  input.focus();
  input.setSelectionRange(2, 5);
}

Specification
HTML
# dom-textarea/input-setselectionrange-dev


Web Proxy Viewer  |  New URL  |  Original Page