Jump to content

Copying a DOM Object


ThePsion5

Recommended Posts

I'm trying to create a function in javascript that allows additional HTML elements to be added to a document by calling the function (preferably a button). I'm relatively new to Javascript but I think I have most of the code here correct. However, I'm not sure how to make a copy of a DOM object in javascript. How would I go about doing this?P.S. Also, if anything else is screwy, let me know :)

var num = 1;		//Tracks the number of fieldsvar containerID;   //The ID of the html element that contains the fields to be addedvar firstID;		   //The ID of the first field elementvar addID;		   //The ID of the element that calls the functionvar maxEntries;	//The maximum number of elementsfunction addFields(){  num++;  if(num < maxEntries)  {	//Retrieve the container's HTML	var ContainerHTML = document.getElementById(containerID).innerHTML;	//Retrieve the HTML code for the first element	var EntryObject = document.getElementById(firstID);	//I need to make a copy of the Entry object here, how would I do this?	//Set the ID of the copied element appropriately	Copy.id = firstID + '_' + num;	//Add the new section to the container's content	document.getElementById(containerID).innerHTML = ContainerHTML + Copy.outerHTML;  }  else  {	document.getElementByID(addID).style.display = "none";  }}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...