0

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);
3
  • 1
    you haven't set background color Commented Mar 15, 2015 at 6:08
  • Are you getting some error?...you didn't write anything in the div, try div.innerHTML = 'hi'; Commented Mar 15, 2015 at 6:12
  • I'm not too sure how to run the code Commented Mar 15, 2015 at 6:18

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

I added background color but am I link tagging the javascript correcting in my html? how would I run this in Sublime Text 2?
1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.