Let’s say before my webapp starts, I want to create all dom elements initially and store them in some preloaded array. Something like:
for (i = 1...100) { preLoader.push($('<div id="' + i + '" />')); }
and then later, depending on the action, I will take the correct element from the array and append it to the DOM.
Now my question is: if I were to later do:
$(div#i).remove()
will it also affect my preLoader array, or is it a different reference than the one in the DOM?
No, it will not. Object will be removed from memory, only and only if there are no ways to access it, that is no references to it. After
$('div#'+i).remove(), you can’t access it from the DOM, but you can still access it bypreLoader[i-1].So you need to remove the object frompreLoaderarray explicitly: