I'm currently a newbie to javascript just started learning on how to create new DOM element using the javascript function document.createElement(). The problem is that I'm getting really confused by all these function.The code be low is what I'm trying to create
I'm getting confused on how to append these element to the element having the id "date". Here is what i've done so far
function createElements(){
//creating <div class="divider"></div>
var div = document.createElement('div');
var attributeDivider= document.createAttribute('class');
attributeDivider.value="divider";
div.setAttributeNode(attributeDivider);
//creating <div class="section"></div>
var div2 = document.createElement('div');
var attributeSection = document.createAttribute('class');
attributeSection.value ="section";
div2.setAttributeNode(attributeSection);
//creating h5
var h5 = document.createElement('h5');
var attributeH5 = document.createAttribute('id');
attributeH5.value ="test";
// creating stuff
var stuff = document.createElement('Stuff');
// creating date
var date = document.getElementById("date");
date.appendChild(h5);
}
<!--This_is_where_I_need_to_append the created elements-->
<p id="date">Date Created</p>
<!--The elements that I need to create-->
<div class="divider"></div>
<div class="section">
<h5>Section 1</h5>
<p>Stuff</p>
</div>
Could someone help me ?