Reputation: 35
I'm doing the odin project and for the front-end webdev project, I have to create a grid using javascript/jQuery. I tried using the createElement method but I was wondering how I would be able to make the div visible in html? Am I going about this all wrong?
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Etch-a-Sketch</title>
<link rel="stylesheet" type="text/css" href="etch-a-sketch.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type = "text/javascript" src="etch-a-sketch.js"></script>
</head>
<body>
</body>
</html>
JS:
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.color = "blue";
document.body.appendChild(div);
Upvotes: 0
Views: 2028
Reputation: 20633
Add more styling to make it visible, such as a border or background color.
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.color = "blue";
div.style.backgroundColor = "blue";
document.body.appendChild(div);
Upvotes: 1
Reputation: 571
Add background-color
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.color = "blue";
div.style.backgroundColor = "yellow";//you forgot background color
document.body.appendChild(div);
Upvotes: 2