--- title: Selection.toString() slug: Web/API/Selection/toString translation_of: Web/API/Selection/toString ---
{{ ApiRef("DOM") }}{{SeeCompatTable}}

Selection.toString() 메소드는 selection 객체가 현재 나타내는 문자열을 반환합니다. 즉, 현재 선택된 텍스트의 문자열.

Syntax

str = sel.toString()

Return value

A string representing the selection.

Description

This method returns the currently selected text.

In JavaScript, this method is called automatically when a function the selection object is passed to requires a string:

alert(window.getSelection()) // What is called
alert(window.getSelection().toString())  // What is actually being effectively called.

Specifications

Specification Status Comment
{{SpecName('HTML Editing', '#dom-selection-stringifier', 'Selection.toString()')}} {{Spec2('HTML Editing')}} Initial definition

Browser compatibility

{{Compat("api.Selection.toString")}}

See also