You are here: Reference > JavaScript > client-side > HTML DOM > methods > substringData (comment, CommentNode, TextNode)
substringData method (comment, CommentNode, TextNode)
Returns the part of the current element's text content from the specified position with the specified length.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. Integer that specifies the zero-based start index. | |||||||
Required. Integer that specifies the maximum number of returned characters. |
Return value:
String that contains the specified segment of text.
Example HTML code 1:
This example illustrates the use of the substringData method:
|
||||
<head> <script type="text/javascript"> function GetLastTwo () { var container = document.getElementById ("container"); var textNode = container.firstChild; var lastTwo = textNode.substringData (textNode.data.length - 2, 2); // or: // var lastTwo = textNode.data.substr (textNode.data.length - 2, 2); alert (lastTwo); } </script> </head> <body> <div id="container">12345678</div> <br /> <button onclick="GetLastTwo ()">Get the last two characters</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments