Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JavaScript / HTML In this project you'll be writing 12 short functions and attaching them to 12 buttons in order to demonstrate the use of
JavaScript / HTML
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.
- Create an unordered list of the following general college majors.
- Computers (add id="computers" to this element)
- Business
- Auto Technology
- Healthcare
- Within each general college major, code at least 3 specific subareas within the major using unordered list elements. For example, within Computers list the following:
- Networking (add id="networking" to this element)
- Web Development (add id="web" to this element)
- Data Analytics (add id="data" to this element)
- Validate your HTML. The JavaScript will not work correctly unless your HTML lists are coded correctly.
- Below your HTML lists, add an h2 element with the text: Methods to traverse the DOM tree
- Below the heading, create one button element for each of the following methods. The button should run a function that completes the task described to the right of the button. Use the specified method as the button label.
- `getElementbtById()`: Get the element with id="computers" and set the text color to #00f (blue)
- `querySelector()`: 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)
- `getElementsByClassName()`: Get the elements with a class="favorite" and set the text color to #0f0 (green)
- `getElementsByTagName()`: Get the elements with a tag name of h2 and set the background color to #0f0 (green)
- `querySelectorAll()`: Get all of the elements with a class="favorite" and set the text color to #0ff (turqoise)
- Below the list of DOM tree methods, add an h2 element with the text: Properties to modify the DOM tree
- Below the heading, create one button element for each of the following properties. Use the specified property as the button label:
- `parentNode`: Change the textContent property of the parent of the element with id="networking" to Show me the money!
- `previousSibling`: 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 ★
- `nextSibling`: Change the textContent property of the next sibling of the element with id="web" to Data Science
- `className`: 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.)
- Below the list of DOM tree methods, add an h2 element with the text: Methods to modify the DOM tree
- Below the heading, create one button element for each of the following methods (or combination of methods). Use the specified method(s) as the button label.
- `createElement() createTextNode() appendChild()`: 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.
- `removeChild()`: 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.
- `hasAttribute() removeAttribute()` 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".)
- Write a JavaScript function, one per button, given the instructions beside the button.
- Run all functions using event listeners.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started