JavaScript DOM Scripting By Example Editing and Filtering Names Saving Names

Israel Hernandez
Israel Hernandez
Full Stack JavaScript Techdegree Student 3,947 Points

Why do we need the li.insertBefore(span, input); ?

I do not understand the purpose of putting the insertBefore method to replace the current input.

2 Answers

Steven Parker
Steven Parker
170,248 Points

The insertBefore method is primarily just a way to add the new element to the DOM, and it has the benefit of allowing it to be placed directly before the element that is about to be removed.

Then when the other element is removed, you can be certain that the new one is in exactly the same spot in the DOM arrangement where the other one was previously.