ioustinos_sarris
asked on
javascript clone object
Hi there, i am looking for a way to clone objects. I have found variations of clonig methods but all seem to be questioned by others...Could anyone suggest a sure and stable clone method?
Note that i need DEEP cloning...
Moreover, if i want to simplify things and know beforehand which objects i need to be cloning, can't i just create a property function in these objects? what would that be?
thanks
Note that i need DEEP cloning...
Moreover, if i want to simplify things and know beforehand which objects i need to be cloning, can't i just create a property function in these objects? what would that be?
thanks
Can you please explain what you mean by "DEEP cloning"
Here is a example which can clone entire table
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<script language="javascript">
function UpdateTable (tableId, divId) {
var tObj = document.getElementById (tableId);
var dObj = document.getElementById (divId);
var nObj = tObj.cloneNode (true);
dObj.appendChild (nObj);
tObj.parentNode.removeChil d (tObj);
alert (dObj.outerHTML);
}
</script>
<table id="mytable"><tr><td>test< /td></tr>< /table>
<div id="mydiv"></div>
<input type="button" value="Insert Table in Div" onClick="UpdateTable ('mytable'
, 'mydiv')">
</body>
</html>
Here is a example which can clone entire table
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<script language="javascript">
function UpdateTable (tableId, divId) {
var tObj = document.getElementById (tableId);
var dObj = document.getElementById (divId);
var nObj = tObj.cloneNode (true);
dObj.appendChild (nObj);
tObj.parentNode.removeChil
alert (dObj.outerHTML);
}
</script>
<table id="mytable"><tr><td>test<
<div id="mydiv"></div>
<input type="button" value="Insert Table in Div" onClick="UpdateTable ('mytable'
, 'mydiv')">
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I was referring to second part of the question
>> Moreover, if i want to simplify things and know beforehand which objects i need to be cloning, can't i just create a property function in these objects?
In object being cloned, he wants to ignore certain child objects ??
>> Moreover, if i want to simplify things and know beforehand which objects i need to be cloning, can't i just create a property function in these objects?
In object being cloned, he wants to ignore certain child objects ??
parvinasar: Please accept my apologies. I didn't notice that it was you who had made the update.
>> Moreover, if i want to simplify things and know beforehand which objects i need to be cloning, can't i just create a property function in these objects?
To my knowledge, no such property, or mechanism exists.
>> Moreover, if i want to simplify things and know beforehand which objects i need to be cloning, can't i just create a property function in these objects?
To my knowledge, no such property, or mechanism exists.
Thanks for the grade & points.
Good luck & have a great day.
Good luck & have a great day.
http://www.java2s.com/Code/JavaScriptReference/Javascript-Methods/cloneNode.htm
There is a cloneNode method...