Share on Google+Share on Google+

JavaScript duplicate method

JavaScript's duplicate method creates a duplicate copy of the specified text range.

JavaScript duplicate method


JavaScript's duplicate method creates a duplicate copy of the specified text range. In this example code we have called the duplicate method on the text range object to create a duplicate copy of that text and then it will be displayed through the alert() method. This method duplicate is applied to the "textrange". Syntax for using the duplicate method is as follows:



Description of code:

In this html page we have created a html page with the one text box and one button. When button is clicked it takes the value from the text box and on it creates the text range and thereafter we have called the duplicate() method on it. When button is clicked it calls the method duplicateFunc() method defined in the JavaScript.

<script language="JavaScript">
function duplicateFunc() {
  var textValue = txt.createTextRange();
   alert("No text to display");
<p align="center">&nbsp;</p>
<div style="background: #cf2255; width:'100%';" align="center">
  <font color="#ffffcc" size="12pt"><b>Duplicate Example</b></font></div>
  <div style="background: #ffffcc; width:'100%';" align="center">
<input type="text" id="txt" value="" />
<button id="myButton" onclick="duplicateFunc();">Call Duplicate</button>


Enter some text into the text box and click on the "Call Duplicate" button.

Download Source Code



Posted on: January 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JavaScript duplicate method  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image