This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

text

Summary

Sets or retrieves the text contained within the range.

Property of dom/TextRangedom/TextRange

Syntax

var result = textRange.text;
textRange.text = value;

Return Value

Returns an object of type StringString

the contained text.

Examples

The following example feature tests for getSelection support and extracts the text contained within the bounds of the range(s) object(s).

function showText(){
if(window.getSelection){
    var buf='';
    var sel=document.getSelection();
    for(var I=0;i<sel.rangeCount;i++)
    {
        var range=sel.getRangeAt(i);
        buf+=range.extractContents().textContent;
    }
    alert(buf);
}else{
    var sel=document.selection;
    if(sel){
        var rng=sel.createRange();
        if(rng!=null){
            alert(rng.text);
        }
        }
}
}

Usage

 Used to extract only the text content from a range.

Attributions