You are here: Reference > JavaScript > client-side > selection and ranges > methods > duplicate (TextRange)
duplicate method (TextRange)
10.5 |
Returns an exact copy of the current TextRange object.
Similarly, use the cloneRange method to clone a Range in other browsers.
Syntax:
You can find the related objects in the Supported by objects section below.
Return value:
Returns the newly created TextRange object.
Example HTML code 1:
This example illustrates the use of the duplicate method:
|
||||
<head> <script type="text/javascript"> function CloneARange () { // Internet Explorer if (document.createRange) { // all browsers, except IE before version 9 var rangeObj = document.createRange (); rangeObj.selectNodeContents (document.body); var rangeClone = rangeObj.cloneRange (); alert (rangeClone.toString ()); } else { // Internet Explorer before version 9 if (document.body.createTextRange) { var rangeObj = self.document.body.createTextRange (); var rangeClone = rangeObj.duplicate (); alert (rangeClone.htmlText); } } } </script> </head> <body> <button onclick="CloneARange ();">Clone a range!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments