Home > Web Front-end > JS Tutorial > First introduction to javascript document fragmentation_javascript skills

First introduction to javascript document fragmentation_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:23:15
Original
1143 people have browsed it

Later, a technical group asked about the following piece of code:

Copy code The code is as follows:

function html2node(s) {
var d = document.createElement('div');
d.innerHTML = s;
if (d.childNodes.length == 1)
return d.childNodes [0];
var df = document.createDocumentFragment();
while (d.firstChild)
df.appendChild(d.firstChild);
return df;
}

I understand the general principles, but what is more confusing is why document.createDocumentFragment is used?
After searching for relevant resources on the Internet, I found out that document.createDocumentFragment is used to create document fragments.
When we need a large number of appendChild page elements, we can first appendChild these elements into document.createDocumentFragment.
Then just appendChild the document fragment to the page. This eliminates the need to refresh the page multiple times to achieve performance optimization. I think the use of document fragments in the above code is redundant.
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template