Code skill Adding new HTML elements

Here you can see how you can use the createElement and appendChild methods to add a new HTML element to your app. To do this you need to create a function that creates a new <div> and sets the innerHTML of that <div> to some text. Then use getElementById to find the new <div> and use appendChild to add another <div>. Then add an onclick to your first <div> that will call your function. So when the existing HTML element is clicked, a new HTML element will be added underneath it.

See the Pen M3 CS Adding new HTML elements by Walker Books UK (@walkerbooks) on CodePen.