JS node using fragment node

Source: Internet
Author: User

JS node, are aware of 3 major categories:

ELEMENT node

Attribute node

Text node

The common element node, the attribute node. There are two ways, SetAttribute () getattribute (), setting and getting property values

In the actual work, long we get a bunch of data from backstage, to show on the front page.
After we have written an HTML master, we use the For loop to add data to the master and finally insert the page. This is the idea!

In order to be quick and convenient, often doing so,

var str= "";

for (Var i=0;i<data.length;i++) {

str+= "<div>" +data[i].detail+ "</div>";

}

$ (' div '). Innerhtml=str;

But this, the impact of page performance, in setting some properties of what is inconvenient, too many strings splicing error, it is important to appear very unprofessional!!

Under the great God's point, start with this ghost!

var fragment=document.createdocumentfragment ();

Fragment is a node fragment.

Now we can do this.

for (Var i=0;i<data.length;i++) {

var div=document.createelement (' div ');

Div.classname= "ML";

Div.innerhtml=data[i].detail;

Fragment.appendchild (DIV);

}

$ (' div '). appendchild (fragment);

So look at the big on it!!!

JS node using fragment node

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.