I am new to javascript, thus I'm trying to teach myself the basics without using packages like JQuery, in order to better understand the language.
My question is in regards to creating an html tag within another html tag using only javascript, I can't seem to do this without getting an error (posted at the bottom).
For example what I have been trying to do is make the element children of each other through the following:
<!doctype html>
<html>
<head>
</head>
<body>
<script>
var element1 = document.createElement("div");
var element2 = document.createElement("svg");
var element3 = document.createElement("rect");
element1.setAttribute('id', 'div1');
element2.setAttribute('id', 'out');
//This is where I fall short
//One way i have tried
document.getElementById('div1').appendChild(element2);
document.getElementById('out').appendChild(element3);
//another way I have tried
document.getElementByClassName('div').appendChild(element2);
//last way I tried
document.getElementById('div1').innerHTML = element2;
</script>
</body>
</html
Although, i have been trying to make this work I have been coming up short and because of this I keep getting the error
"TypeError: 'null' is not an object (evaluating 'document.getElementBy(Id/ClassName)
().innerHTML/appendChild')
Any help is greatly appreciated! Also, if it's not too much to ask, since i am still trying to understand the javaScript concepts please explain your response.