DOM Objects Worksheet

Question 1

In order to use the document.getElementById() method to 'get a handle' on an element, what attribute must that element have?

To use 'document.getElementById()', the element must have an 'id-attribute'.
Example:

                    div> id="myElement">hello! /div>

                    let greeting = document.getElementById("myElement");
                    console.log(greeting.innerHTML); // output should be: "hello!"
                

Question 2

When you invoke document.getElementById(), you must pass in a string parameter. What does the parameter represent?

The string parameter represents the id-attribute of the element. This allows the attribute to return that reference specified in that element.

Question 3

What does the document.getElementById() method return?

The 'document.getElementById()' returns a reference to the specified id-attribute. This lets you reference the properties of the element.

Question 4

What object is at the top of the DOM? In other words, what DOM object contains all other DOM objects?

The document-object is at the top of the DOM. It represents the entire HTML document and serves as the root-object, which contain all the elements and objects in the DOM hierachy.


Coding Problems

You'll use the following elements to complete the coding problems:

Problem 1


Problem 2
A bald eagle

Problem 3
This is myDiv


Problem 4

Sign Up Form

Complete this form to sign up