Hi everyone,
I have been trying to fix this issue by visiting the forums here and there
and also tried to do exactly what I learned from them yet, I am unable
to add a div to another one. The error message in the console is :
Uncaught TypeError: Cannot read property 'appendChild' of undefined
And the code that I have been using is as follows. Could you please help me with this issue?
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>1js</title>
<style type="text/css">
div.box {
background-color: hsl(0, 0%, 0%);
margin-left: 15px;
width: 20px;
height: 20px;
}
div.wrapper {
width: 400px;
height: 200px;
background-color: green;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper"> </div>
<script type="text/javascript">
var wrappers = document.getElementsByClassName("wrapper");
var newDiv = document.createElement("div.box");
document.wrappers.appendChild(newDiv);
}
</script>
</body>
</html>