Home > Web Front-end > JS Tutorial > body text

JavaScript code for cloning nodes using cloneNode method_javascript skills

WBOY
Release: 2016-05-16 17:49:00
Original
1724 people have browsed it

Many times we use for to generate multiple node structures with the same structure, so we need to write a lot of createElement, setAttribute, appendChild and other codes.

But in fact, we only need an html template, and we can use the cloneNode method to clone existing nodes, including their child nodes.
The following is the cloneNode method prototype:

newElement oldElement.cloneNode(bool deep);

This method has only one parameter deep, a Boolean value. If it is true, clone oldElement and this child node, otherwise only the node itself.

The return value is a cloned node newElement.

The following is the test code, test.htm and test.js files.

Copy code The code is as follows:




Test of cloneNode Method
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!