Why should I use .createElement instead of .innerHTML?

Question

Why should I use .createElement instead of .innerHTML?

Answer

The main advantage for using .createElement is that .createElement will not replace the inner HTML that the newly created element is appended to (using .appendChild). Setting the .innerHTML on an element however, will replace any content or DOM nodes that are inside the element.