'TextRange' Example : TextRange « Javascript Objects « JavaScript Reference

'TextRange' Example

    
<html>
<head>
<script language="javascript">
function displayText(){
    textRange = document.all.myBody.createTextRange();
    textRange.moveToElementText(myP);
    var m = textRange.text;
    alert(m); 
} 
</script></head>
<body id="myBody">
<p id="myP">This is some text in the document inside a p element</p>
<button onclick="displayText();">Display the text range</button>
</body>
</html>

    
      
      








Related examples in the same category

1.'TextRange' Syntax and Note
2.'TextRange' JavaScript Properties
3.'TextRange' JavaScript Methods