clonenode

Native way to copy all child nodes to an other element

你离开我真会死。 提交于 2019-11-29 18:03:15
I have to change "unknown" contents of XML. The structure and content itself is valid. Original <blabla foo="bar"> <aa>asas</aa> <ff> <cc> <dd /> </cc> </ff> <gg attr2="2"> </gg> ... ... </blabla> becomes <blabla foo="bar"> <magic> <aa>asas</aa> <ff> <cc> <dd /> </cc> </ff> <gg attr2="2"> </gg> ... ... </magic> </blabla> thus, adding a child straight under document root node (document.documentElement) and "pushing" the "original" children under that. Here it has to be done in plain javascript (ecmascript). The idea now is to // Get the root node RootNode = mymagicdoc.documentElement; // Create

Cloned elements cannot be submitted in Angular4

前提是你 提交于 2019-11-29 12:22:35
I have a template with two fields for.eg name and age, that needs to cloned and appended to the same container. I achieved this using the following code. html file <ng-template #tpl> <div class="form-group"> <input type="text" id="name" class="form-control" name="name" ngModel #name="ngModel"> <input type="text" id="age" class="form-control" name="age" ngModel #age="ngModel"> <button type="Button" >Remove</button> </div> </ng-template> <div>Some element</div> <form #myForm="ngForm" novalidate (ngSubmit)="save(myForm)"> <div #container> </div> <button type="submit">Submit</button> </form>

Native way to copy all child nodes to an other element

青春壹個敷衍的年華 提交于 2019-11-28 12:26:37
问题 I have to change "unknown" contents of XML. The structure and content itself is valid. Original <blabla foo="bar"> <aa>asas</aa> <ff> <cc> <dd /> </cc> </ff> <gg attr2="2"> </gg> ... ... </blabla> becomes <blabla foo="bar"> <magic> <aa>asas</aa> <ff> <cc> <dd /> </cc> </ff> <gg attr2="2"> </gg> ... ... </magic> </blabla> thus, adding a child straight under document root node (document.documentElement) and "pushing" the "original" children under that. Here it has to be done in plain javascript

Clone element with all its events

送分小仙女□ 提交于 2019-11-26 21:13:27
问题 I'm cloning a textarea in a page but the cloned element doesn't have any event of the primary element, is there any way to clone all events in cloned element? var dupNode = node.cloneNode(deep); 回答1: You can maybe use getEventListeners on nodes? Don't know how the support is, or if it's only supported in the console? function cloneMassive(node) { // Clone the node, don't clone the childNodes right now... var dupNode = node.cloneNode(false); var events = getEventListeners(node); for(var p in