0

I am currently creating a project and I'm new to JS, html and CSS.

Is it possible to get the original data or <div> after I cloned it?

Here is my sample code:

let currentId = 1;
function addQuestionaire() {
    let tmpl = document.getElementById('tmp1_id1');
    let clone = tmpl.cloneNode(true);
    let div = clone.querySelector('#selectionArea');
    currentId += 1;
    div.id = `tmp1_id${currentId}`;
    tmpl.parentNode.insertBefore(clone, tmpl.nextSibling)

    return div.id;
}
Martijn
  • 15,791
  • 4
  • 36
  • 68
Lep
  • 21
  • 2
  • 9
  • Cloning will not modify the original. – Poul Bak Nov 02 '18 at 14:02
  • unclear what you mean – epascarello Nov 02 '18 at 14:02
  • cloning will not modifiy the original, you can check this link to get better idea about what you want https://stackoverflow.com/questions/18735935/how-to-remove-original-element-after-it-was-cloned – Steve Ruben Nov 02 '18 at 14:03
  • in my
    i have a
    Then I change the value of my one option to 2. Is there a way to get the original div? after I changed it. in my case im getting the clone and I can't go back to its original value. another example is I have textarea inside my div and I'm putting a value then I can get the value after I clone but how can I set or get the original value of my textarea if there is sa default value or place holder.
    – Lep Nov 02 '18 at 14:05
  • Hi Steve Ruben. I actually saw that jquery code but I'm looking on javascript since im working on pure javascript alone. TIA – Lep Nov 02 '18 at 14:07
  • @PhilipCrisFaisalDuterte you can learn more about clone on w3school – Steve Ruben Nov 02 '18 at 14:08

0 Answers0