Search code examples
javascriptdomappendchildclonenode

Does order of appending child nodes matters?


I have the following code:

span.appendChild(link);
span.appendChild(closeButton);
closeButton.appendChild(closeIcon);

What if I append closeIcon to closeButton before appending closeButton to span? Is there any difference? And is there any difference between cloned nodes inserted to DOM with js and the ones that are hardcoded in html?


Solution

  • The nodes will be added to the DOM in the order you define, however, their visual appearance may represent different ordering due to the elements' CSS properties.