当前位置:网站首页>Cloning and importing DOM nodes
Cloning and importing DOM nodes
2022-06-25 06:39:00 【InfoQ】
Preface
node.cloneNode()
node.cloneNode()grammar
let cloneNode = targetNode.cloneNode(deep);
- cloneNode The node copy generated by the final Clone .
- targetNode The target node to be cloned .
- deep Optional parameters , Indicates whether deep cloning is required , That is, whether you need to clone targetNode Child nodes under , The default is false.
<body>
<div id="container">
<div class="header"> This is the head </div>
<div class="body">
<div class="content"> Content of a </div>
<div class="content"> Content of the two </div>
</div>
</div>
<script>
const target = document.querySelector(".body");
const cloneNode1 = target.cloneNode();
console.log("cloneNode1.outerHTML\n\n",cloneNode1.outerHTML);
const cloneNode2 = target.cloneNode(true);
console.log("cloneNode2.outerHTML\n\n", cloneNode2.outerHTML);
</script>
</body>

document.importNode()
let node = document.importNode(externalNode, deep);
- node The node object imported externally into the current document .
- externalNode The target node to be imported in the external document .
- deep Deep copy or not , The default is false.
<!--iframe.html-->
<body>
<h1> This is a Iframe page </h1>
<div id="container">
<div class="header"> This is a Iframe Content header </div>
<div class="body"> This is a Iframe Content subject </div>
</div>
</body>
<!--index.html-->
<body>
<div id="container">
<div class="header"> Content header </div>
<div class="body"> Content subject </div>
</div>
<iframe id="iframe_ele" src="./iframe.html"></iframe>
<script>
window.onload = function () {
const iframeEle = document.getElementById('iframe_ele');
const iframeContainer = iframeEle.contentDocument.getElementById("container");
const importedNode = document.importNode(iframeContainer, true);
document.body.appendChild(importedNode);
}
</script>
</body>

document.adoptNode()
ownerDocumentlet node = document.adoptNode(externalNode);
- node Node object obtained from external document .
- externalNode The node object in the external document to be imported .
<!--iframe.html-->
<body>
<h1> This is a Iframe page </h1>
<div id="container">
<div class="header"> This is a Iframe Content header </div>
<div class="body"> This is a Iframe Content subject </div>
</div>
</body>
<!--index.html-->
<body>
<div id="container">
<div class="header"> Content header </div>
<div class="body"> Content subject </div>
</div>
<iframe id="iframe_ele" src="./iframe.html"></iframe>
<script>
window.onload = function () {
const iframeEle = document.getElementById('iframe_ele');
const iframeContainer = iframeEle.contentDocument.getElementById("container");
const node = document.adoptNode(iframeContainer);
document.body.appendChild(node);
}
</script>
</body>

summary
边栏推荐
- Derivation of COS (a-b) =cosa*cosb+sina*sinb
- Exercise: completion
- Difference between rest and WebServices
- Go language library management restful API development practice
- The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
- Derivation of sin (a-b) =sina*cosb-sinb*cosa
- Streaming a large file using PHP
- Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals
- @Detailed explanation of valid annotation usage
- Cve-2022-23131 - bypass SAML SSO authentication
猜你喜欢

Understand what MTU is

Derivation of COS (a+b) =cosa*cosb-sina*sinb

JSON. toJSONString(object, SerializerFeature.WriteMapNullValue); Second parameter action

Sophomores majoring in mechanics build a manipulator by hand -- full of compromise

Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)

Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution

JS dynamic table creation
![[short time energy] short time energy of speech signal based on MATLAB [including Matlab source code 1719]](/img/a1/0cb61368cb1d0817d74781084a4466.jpg)
[short time energy] short time energy of speech signal based on MATLAB [including Matlab source code 1719]

2022-02-19: fence installation. In a two-dimensional garden, there are some trees represented by (x, y) coordinates. As the installation cost is very expensive, your task is to enclose all the trees w

Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals
随机推荐
The "&" character will destroy the data stored in the web The "&" character breaks passwords that are stored in the web config
@Detailed explanation of valid annotation usage
Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution
What is the IP address
Your local changes to the following files would be overwritten by merge: .vs/slnx.sqlite
What is VLAN
How do I check swift if two arrays contain the same elements, regardless of the order in which they appear?
Cs5092 5V USB input boost two section lithium battery charging management IC, SOT23-6 miniature package
The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
Why study discrete mathematics
JS dynamic table creation
R & D thinking 07 - embedded intelligent product safety certification required
What does cardinality mean in set
How to create a handy vs Code?
keil debug查看变量提示not in scope
Go language library management restful API development practice
Navicat防止新建查询误删
Controlling volume mixer
アルマ / 炼金妹
原子Alpha开发板--SD卡和emmc烧录工具