当前位置:网站首页>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
边栏推荐
- Observation configuring wmic
- MSG_ OOB MSG_ PEEK
- Missing libgmp-10 dll - libgmp-10. dll is missing
- Why can't GC () free memory- Why does gc() not free memory?
- Derivation of COS (a-b) =cosa*cosb+sina*sinb
- You can see the classification of SQL injection. SQL injection point /sql injection type /sql injection has several /sql injection point classifications
- [core content and derivation] the mystery of human memory system may be just like this
- Difference between rest and WebServices
- [speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]
- General test point ideas are summarized and shared, which can be directly used in interview and actual software testing
猜你喜欢

In depth inventory: 23 vscode plug-in artifacts that improve development efficiency and aesthetics

How to find happiness in programming and get lasting motivation?

Ht513 I2S input 2.8W mono class D audio power amplifier IC

Gb28181 protocol -- timing

DNS domain name system

The five minute demonstration "teaches" actors to speak foreign languages and can seamlessly switch languages. This AI dubbing company has just received a round a financing of 20million US dollars

Meta universe is over, Web 3.0 will be fooled again?

Cs4344/ht5010 stereo d/a digital to analog converter

使用OpenGL绘制shp文件

Sophomores majoring in mechanics build a manipulator by hand -- full of compromise
随机推荐
What is VLAN
With a younger brother OCR, say no to various types of verification codes!
[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]
An interview question record about where in MySQL
Leetcode 2163. Minimum difference of sum after element deletion
You can see the classification of SQL injection. SQL injection point /sql injection type /sql injection has several /sql injection point classifications
Preliminary practice of niuke.com (summary)
In a single-page app, what is the right way to deal with wrong URLs (404 errors)?
Meta universe is over, Web 3.0 will be fooled again?
How to record a database [closed] - how to document a database [closed]
集群常用群起脚本
Is it safe to open a stock account on the Internet in Beijing?
ASP. Net core - Safety of asynclocal in asp NET Core
JS to determine whether an element exists in the array (four methods)
十大券商公司哪个佣金最低,最安全可靠?有知道的吗
How to create a handy vs Code?
PHP converts strings to hex and hex to string - PHP convert string to hex and hex to string
mysql 表查询json数据
How to realize hierarchical management of application and hardware in embedded projects
@Detailed explanation of valid annotation usage