I'm trying to create a clone of a div Element with the method cloneNode and then I want to set the id of the clone with the setAttribute method, but I get this error:
Property 'setAttribute' does not exist on type 'Node'.
Here is my HTML:
<div id="containerParentId" class="row boundary">
<div class="col no-padding" id="containerId"
(drop)="onDrop($event)"
(dragover)="onDragOver($event)"
(dragleave)="onLeave($event)">
<div class="vl" id="verticalLine" ></div>
<div id="divTable" class="tableOnePosition"
draggable="true"
(dragstart)="onDragStart($event)"
(drag)="onDrag($event)"
(dragend)="onDragEnd($event)"
></div>
</div>
And here is the js code:
let clone = document.getElementById('divTable').cloneNode(true);
clone.setAttribute('id','newId');
I'm using Angular as my frontend framework.
I have read different questions about this and it should be possible as far as I can see. An example is this question: Is it possible to clone html element objects in JavaScript / JQuery?