Lightest DOM Object

I wanted to know what is the easiest HTML element. Have a huge JSON dataset that I have to display in a readable format, therefore iterate over the data and create dynamic elements. This is the lightest HTML element, the lightest, which takes up the least amount of memory and is easily displayed by the browser, etc.

EDIT : will use Mootools, so don't worry about the creation part. Will use ordinary. This is what I'm going to do.

objJson.each(function(j, jCounter)
{
     var elm = new Element('', {'html' : j.value}).injectInside($(document.body));
});

Tell me, which new item is best to create?

+3
source share
5 answers

divs. , , , , ( ) . , , , .

JS- ( ) .

+1

, . , .

, .innerHTML , .

document.createElement('span') , , span , .cloneNode(true) , ( , ).

, , , jQuery, , .


UPDATE

, - , . , div span , .

, , , innerHTML.

+1

@Kobi, , json .

, .append() , , . - :

var newElements;

for(i=0; i<objects.length; ++i) {
  newElements += "<div>" + objects[i].name + "</div>"
}

$("#container").append(newElements);

div , . . json, , - :

var object;
var newElements;
var objectCount = objects.length;

for(i=0; i<objectCount; ++i) {
  object = objects[i];
  newElements += "<div>" + object.name + ", " + object.size + ", " + object.color + "</div>"
}

$("#container").append(newElements);
+1

, , , .
JSON , HTML.

0

My wild guess spanis if you want him to be able to use CSS the way you want.

0
source

Source: https://habr.com/ru/post/1727504/


All Articles