ThePsion5 Posted August 31, 2006 Share Posted August 31, 2006 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 More sharing options...
aspnetguy Posted August 31, 2006 Share Posted August 31, 2006 var CopyObject = EntryObject; Link to comment Share on other sites More sharing options...
ThePsion5 Posted August 31, 2006 Author Share Posted August 31, 2006 var CopyObject = EntryObject;Ah, I wasn't sure if that would copy the object or just reference it. Thanks! Aside from that, does the code look clean and/or valid? Link to comment Share on other sites More sharing options...
aspnetguy Posted August 31, 2006 Share Posted August 31, 2006 everything looks to be in order Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now