I've been trying to use pure JavaScript (no jQuery) to recreate HTML content within the container. But, nothing shows up on the webpage when I run. I did a lot of research online, but still no luck. Could anyone help me to take a look?
p.s. Sorry about my code is long and messy. If you could help me point out which part of function or format I did wrong and tell me the correct way that would be great! Thank you!
Here is the original code I am trying to duplicate:
<div class="container">
<div class="row">
<div class="col-md-12">
<h3>Nothing clicked yet!</h3>
<button type="button" class="btn btn-default btn-lg">Star</button>
<hr>
<div>
<div class="btn-group">
<button type="button" class="btn btn-default">1</button>
<button type="button" class="btn btn-default">2</button>
<button type="button" class="btn btn-default">3</button>
<button type="button" class="btn btn-default">4</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">5</button>
<button type="button" class="btn btn-default">6</button>
<button type="button" class="btn btn-default">7</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">8</button>
</div>
</div>
<hr>
<div>
<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-default">Left</button>
<button type="button" class="btn btn-default">Middle</button>
<button type="button" class="btn btn-default">Right</button>
</div>
</div>
</div>
</div>
</div>
Here is what I have so far:
function myFunction() {
var makeDiv = document.createElement('DIV');
var makeHead = document.createElement('H3');
var makeBTN = document.createElement('BUTTON');
var swapH3 = function swap() {
//locate button textNode then use it to replace the text inside of h3;
};
var rowDiv = document.getElementById("container").appendChild("makeDiv");
rowDiv.className = "row";
rowDiv.id = "row";
var colDiv = document.getElementById('row').appendChild('makeDiv');
colDiv.className = "col-md-12";
colDiv.id = "col";
var head = document.getElementById('col').appendChild('makeHead');
head.id = "head";
head.createTextNode('Nothing clicked Yet!');
var btn0 = document.getElementById('col').appendChild('makeBTN');
btn0.id = "btn0";
btn0.className = "btn btn-default btn-lg on";
btn0.createTextNode = ('star');
btn0.type = "button";
btn0.onclick = swapH3;
document.getElementById('col').appendChild(document.createElement(HR));
var btng1 = document.getElementById('col').appendChild('makeDIV');
btng1.id = 'btng1';
document.getElementById('col').appendChild(document.createElement(HR));
var btng2 = document.getElementById('col').appendChild('makeDIV');
btng2.id = 'btng2';
var btngA = document.getElementById('btng1').appendChild('makeDIV');
btngA.id = 'btngA';
btngA.className = 'btn-group';
var btngB = document.getElementById('btng1').appendChild('makeDIV');
btngB.id = 'btngB';
btngB.className = 'btn-group';
var btngC = document.getElementById('btng1').appendChild('makeDIV');
btngC.id = 'btngC';
btngC.className = 'btn-group';
var btngD = document.getElementById('btng2').appendChild('makeDIV');
btngD.id = 'btngD';
btngD.className = 'btn-group btn-group-lg';
var btn1 = document.getElementById('btngA').appendChild('makeBTN');
btn1.className = 'btn btn-default';
btn1.type = 'button';
btn1.createTextNode = ('1');
btn1.onclick = swapH3;
var btn2 = document.getElementById('btngA').appendChild('makeBTN');
btn2.className = 'btn btn-default';
btn2.type = 'button';
btn2.createTextNode = ('2');
btn2.onclick = swapH3;
var btn3 = document.getElementById('btngA').appendChild('makeBTN');
btn3.className = 'btn btn-default';
btn3.type = 'button';
btn3.createTextNode = ('3');
btn3.onclick = swapH3;
var btn4 = document.getElementById('btngA').appendChild('makeBTN');
btn4.className = 'btn btn-default';
btn4.type = 'button';
btn4.createTextNode = ('4');
btn4.onclick = swapH3;
var btn5 = document.getElementById('btngB').appendChild('makeBTN');
btn5.className = 'btn btn-default';
btn5.type = 'button';
btn5.createTextNode = ('5');
btn5.onclick = swapH3;
var btn6 = document.getElementById('btngB').appendChild('makeBTN');
btn6.className = 'btn btn-default';
btn6.type = 'button';
btn6.createTextNode = ('6');
btn6.onclick = swapH3;
var btn7 = document.getElementById('btngB').appendChild('makeBTN');
btn7.className = 'btn btn-default';
btn7.type = 'button';
btn7.createTextNode = ('7');
btn7.onclick = swapH3;
var btn8 = document.getElementById('btngC').appendChild('makeBTN');
btn8.className = 'btn btn-default';
btn8.type = 'button';
btn8.createTextNode = ('8');
btn8.onclick = swapH3;
var btnLeft = document.getElementById('btngD').appendChild('makeBTN');
btnLeft.className = 'btn btn-default';
btnLeft.type = 'button';
btnLeft.createTextNode = ('Left');
btnLeft.onclick = swapH3;
var btnMiddle = document.getElementById('btngD').appendChild('makeBTN');
btnMiddle.className = 'btn btn-default';
btnMiddle.type = 'button';
btnMiddle.createTextNode = ('Middle');
btnMiddle.onclick = swapH3;
var btnRight = document.getElementById('btngD').appendChild('makeBTN');
btnRight.className = 'btn btn-default';
btnRight.type = 'button';
btnRight.createTextNode = ('Right');
btnRight.onclick = swapH3;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container" id="container">
</div>
innerHTMLwill allow you to get/set the contents of an HTML element, so why would you want to do this? developer.mozilla.org/en-US/docs/Web/API/Element/innerHTMLvar rowDiv = document.getElementById("container").appendChild("makeDiv");is valid, shouldn't it bevar rowDiv = document.getElementById("container").appendChild(makeDiv);?