How to clone a tag and modify the clone tag without changing the original one? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How to clone a tag and modify the clone tag without changing the original one?

I can clone a tag of HTML. Here is the code: https://code.sololearn.com/WA19a23a7A9a Now I need to modify only the cloned tag. How can I do that? Thanks in advance.

16th May 2021, 2:42 PM
The future is now thanks to science
The future is now thanks to science - avatar
6 Answers
+ 4
What do you mean by changing the cloned tag position?
16th May 2021, 2:52 PM
Avinesh
Avinesh - avatar
+ 2
If you want to change the position where the cloned tag is inserted, you can use other methods like prepend (), insertAdjacentElement (), etc.
16th May 2021, 3:06 PM
Eze
+ 1
Avinesh , I mean using top,left,bottom ,right to position the element .
16th May 2021, 3:05 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
Try this 😜 var myDiv = document.getElementById("test").cloneNode(true); myDiv.append(" cloned") document.body.prepend(myDiv);
16th May 2021, 3:34 PM
Eze
+ 1
Change the id of clone
16th May 2021, 8:14 PM
ODLNT
ODLNT - avatar
0
@Eze sorry for asking but can you please give an example as I don't know the use of those tags?
16th May 2021, 3:24 PM
The future is now thanks to science
The future is now thanks to science - avatar