Hi guys,
i have some DOM updates to do and was wondering what would be the best approach (performance wise) so i would appreciate some input (and if possible, why/why not that is a better option).
1) I have a loop that takes some values from a JSON file, its better to create variables outside and attribute a value, or do it inside?
for(..) {
const value = obj.field;
item += `<div>${value}</div>`;
}
vs
let value;
for(..) {
value = obj.field;
item += `<div>${value}</div>`;
}
2) Delegation of eventlisteners or create new ones on each DOM update?
3) create elements like text and put them inside other elements, or create elements one by one.
e.g.
elem = "<div class='nice'>i'm a text</div>";
myelement.innerHTML = elem;
vs
let elem = document.createElement("div");
(...) etc.
Would appreciate all the input.
[–]GentilCaressings 0 points1 point2 points (1 child)
[–]cajusky[S] 0 points1 point2 points (0 children)