Cloning
May 20, 2006How I can make clone of a object in my html document?
I want make copy of a div with some data by clickong a buttun
How I can make clone of a object in my html document?
I want make copy of a div with some data by clickong a buttun
Does anyone know of any generic code to clone an object (which only contains properties), which copies by value, not just reference?
It seems as though there should be some sort of prefab recursive function that could work for any old object, so I didn't want to re-invent the wheel Code:
I'm using a fieldset with a set of form elements as a template, but when I clone the node and try to change the contained element names + ids, they are being set at some point, because I can 'alert' the new names/ids out, but they are not being changed in time to be written to the DOM.
The code is here. Take '?debug' off the address to ditch the alerts.
It's probably a dumb mistake I've made along the way, but I can't see the wood for the trees
Any pointers would be great.
UPDATE: The function in question is 'addDate'. I have a form generated from PHP and I want to clone a group of elements and rename each from 'startTime1[h]' to 'startTime2[h]' etc. but the new elements are keeping the same name 'startTime1[h]'.
I have put together a small script and need to clone all the object boxes so that I can copy from selelct box 2 to textarea 1 after adding new row. I am also looking to copy from autocomplete to the same textarea and have the text fall into the text box on a new line.
See attached code
Code:
I use such code to clone blocks:
element = document.getElementById(IdOfElement)
element = element.cloneNode(true)
new_element = document.getElementById(IdOfElement).appendChild(e lement)
Anybody knows how to set id for the new element ? I mean the id which I coud
use in CSS stylesheet for setting css properties of new element.
I'm new to jquery so I'm having a bit of an issue cloning a table row and having all of the id's change correctly. I'm able to clone a row with no problem and change the id of the tr after clicking a button by doing this:
var newId = document.getElementById("id").value; // This works because I am using a hidden input for my id $(id).clone().attr("id", "row" + newId).insertAfter("#div_id");// This changes the id of row The problem I am having is when I want to change the other id's inside of the tr. After insertAfter() I'll do the following: .find("span").text("Item" + newId).find("#Item_A" + oldId).attr("id", "Item_A" + newId);
The first .find will change the text with no problem, its when I get to Item_A that it will keep the old id instead of incrementing to the new id. Yes, I am declaring oldId as a variable and assigning it as newId - 1. Any ideas on how to make sure all id's are incremented properly?
I've the following html:
Code:
And javascript:
javascript Code:
So what I need to do is to simply clone the row, substitute new values from an array and insert it after the last existing row (if array's size more then 1). But this doesn't work! Where is an error?
I have a form that I want to clone and add up to 5 duplicates with slight changes. The changes are:
Add a second question and another set of related radio buttons for only the duplicates. Change the title in the Header to increment by 1 ex. Header 1, Header 2...
I also would like to make the form elements "id" and "names" unique. Also, continue to use the add and remove button at the bottom.
I have included my existing code.
NOTE: for a visual, I mocked up the the original form and 1 copy of the fields in the html, not to be used.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
[Code]....
Following is the code which will clone a set of div with their events(onclick) which is working fine for FF but in case of IE it is not firing events associated with each div.
<html>
<head>
<style type='text/css'>
.firstdiv{
[Code]....
I have table where is one row(lets called it row template().I try to add new row ito the table by cloning template row.Here is my test table:
<table>
<tr>
<td>
[code]....
I need to .clone() sections in a dynamic form, but get problems withthe radio buttons in IE.To work as a group, the radio buttons need to have the same name (persection). This is accomplished by changing the name attribute aftercloning a hidden section in a <div>. Easy with jQuery! - and it workswith FF, Opera, Chrome, Safari...IE however, does not allow changing of name attribute dynamically, andtreats all radio buttons across the sections as part of the samegroup!!Does anyone know of a workaround, preferably using jQUery, andavoiding browser sniffing and low-level DOM programming?
View 1 Replies View RelatedI am using the little tooltip script below. Normally, works fine, except when I clone an element which has a tooltip in it and append it to another element using something like: $("#table tbody").append($("#row").clone(true));.
Now, immediately after cloning it, I use jQuery to alert the title attribute, and it is in the new element. Then, when I view it using firefox, the title is gone, and obviously the tooltip cannot work.
/**
Vertigo Tip by www.vertigo-project.com
Requires jQuery
*/
[Code].....
I'm writing a dynamic form that allows users to add fields. Thesefields are contained in a table.I have this function to clone the rows (my table has an ID of
EventType)
function addEventType()
{
[code]....
I am currently using this function to clone rows in my table when a user clicks 'add row'
The problem is, obviously, cloning the row also clones any of the data that the user may have already entered. I need to just clone the elements of the row, not the user entered data. Is there a way to remove all data from a row before it is cloned?
I have a form where you can enter 1 player's data, press a button and that DIV gets cloned below with same ID names but numbers get augmented (ie firstName_1 in div player_1 becomes firstName_2 in player_2).
My problem now is I have a Gender radio button and that if you fill out the gender question and then press the 'Add Player' button the checked status seems to disappear from the cloner div but is retained in the clonee div.
IE you can set gender_1 to 'Male' in div player_1 (checked with DOM inspector and console logging) but when stepping thru the code in firebug
[Code]...
I got this code off of this site but when I tried to integrate it in my code it didnt work
Code:
Then I am trying to clone this:
Code:
I am trying to add a field if the user wants to add another field.