This project I am working on, I have a list of elements and convert them into a "graph" (not a true graph, but you can call it a psuedo one). I have my data set, i run a for
loop over the data and then create a li
element for each one, create and parent ul
, append the li
s and then append the parent to another DOM element (we'll call it grandparent) already on the page. After that, i have to make subsequent updates to that list based on user interaction.
Also, this is all in the context of using jQuery.
Now, my question is - is it faster to create the elements once then update the resulting HTML on each subsequent call or is it faster to just recreate each element, empty()
the grandparent element (which would get rid of the parent ul
) and then reappend the newly created ul
(which I am doing now)?
Keep in mind that when I am recreating the li
s, they are not in the DOM at all so there is no repaint/reflow while recreating them. The repaint only happens when I reappend the newly created ul
.
I was speaking to a coworker and he said it would be better to just update the HTML elements once they are created rather than recreating them every single time. i was thinking of going this route, but then I thought that updating the existing li
s would actually cause a repaint on say 50 elements versus just doing one massive one with the empty()
then reappending the newly created ul
.
thoughts?