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);
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);
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.