--- title: Selection.toString() slug: Web/API/Selection/toString translation_of: Web/API/Selection/toString --- <div> <div> <div>{{ ApiRef("DOM") }}{{SeeCompatTable}}</div> </div> </div> <p>Метод <strong><code>Selection.toString()</code></strong> возвращает строку, содержащуюся в выделенном объекте, т.е. выделенный текст.</p> <h2 id="Syntax" name="Syntax">Syntax</h2> <pre class="syntaxbox"><em>str</em> =<em> sel</em>.toString() </pre> <h3 id="Return_value">Return value</h3> <ul> <li><em><code>str</code></em> -- это строка, содержащаяся в выделении.</li> </ul> <h3 id="Parameters" name="Parameters">Parameters</h3> <p><em>None (отсутствуют).</em></p> <h2 id="Description" name="Description">Description</h2> <p>Этот метод возвращает выделенный текст.</p> <p>В <a href="en/JavaScript">JavaScript</a>, этот метод вызывается автоматически, когда функция, которой он передаётся, требует строку:</p> <pre class="brush: js">alert(window.getSelection()) // What is called alert(window.getSelection().toString()) // What is actually being effectively called. </pre> <h2 id="Specifications">Specifications</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> <tr> <td>{{SpecName('HTML Editing', '#dom-selection-stringifier', 'Selection.toString()')}}</td> <td>{{Spec2('HTML Editing')}}</td> <td>Initial definition</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> <p>{{Compat("api.Selection.toString")}}</p> <h2 id="See_also" name="See_also">See also</h2> <ul> <li>{{domxref("Selection")}}, the interface it belongs to.</li> </ul>