where offsetPosition is that specified position where we want to insert data and string carries the data which is to be inserted.
Description of code:
In the following code we are going to illustrate how to use insertData() method for inserting the string text to the specified position in the object. We have created an html page which contains one text input and one button when user clicks on this button it calls the method funcInsertData() in which we gets the position offset value and stores it to the object pos.
var pos = document.getElementById("t1").value;
Further we gets the parent element object to which we have to insert data for example in our code its "para" i.e paragraph.
var m = document.getElementById("para").firstChild;
Now we inserts data "roseindia.net" to the offset position "pos". Here is the full html code for the example as follows:
Please provide the data position to insert data.
After inserting the position click on InsertData Position button. It will insert data
You can also download the full source code for the insertData() method use from the following link.