As always, spell check all content and identify your name and the current date in all files using comments. In html files you may use the html meta tag, e.g. <meta name="author" content="John Doe">
.
<p>
elements with id="q1"
, id="q2"
, and id="q3"
respectively.In this project you'll be writing 12 short functions and attaching them to 12 buttons in order to demonstrate the use of 11 methods and 4 properties introduced in Chapter 5 that allow you to traverse and manipulate the html DOM.
id="computers"
to this element)id="networking"
to this element)id="web"
to this element)id="data"
to this element)h2
element with the text: Methods to traverse the DOM tree
Get the element with id="computers"
and set the text color to #f00 (blue)
Get the first element with class="favorite"
(code the first list item in each of the four major categories (Computers, Business, Auto Technology, Healthcare) with the class="favorite"
) and set the text color to #f00 (red)
Get the elements with a class="favorite"
and set the text color to #0f0 (green)
Get the elements with a tag name of h2
and set the background color to #0f0 (green)
Get all of the elements with a class="favorite"
and set the text color to #0ff (turquoise)
h2
element with the text: Properties to modify the DOM tree
Change the textContent
property of the parent of the element with id="networking"
to Show me the money!
Change the innerHTML
property of the previous sibling of the element with id="web"
to ★ ★ ★ Information Technology ★ ★ ★
Note: The escape code for a solid star is ★;
Change the textContent
property of the next sibling of the element with id="web"
to Data Science
Change the className
property of the element with id="data"
to favorite
(Then click the querySelectorAll button to change the text color of all elements with class="favorite"
to turqoise to see if id="data" also turns turqoise.)
h2
element with the text: Methods to modify the DOM tree
Create a new li
element. Create a new text node for the element with the text Science
. Append the node as a child below Computers, above the Business list item.
In the html, add id="autolist"
to the opening unordered list tag in the Auto Technology area and id="engines"
to the Engines list item. Use those references to remove the Engines list item from the Auto Technology list.
Use the getElementsByTagName()
method to select the second li
element (Networking). If that element has class="favorite"
, remove the attribute. (Test this by using the querySelectorAll button to change the text color of all elements with class="favorite"
.)