Chapter project
Manipulating HTML elements with JavaScript
Take the HTML code below:
<div class="output">
<h1>Hello</h1>
<div>Test</div>
<ul>
<li id="one">One</li>
<li class="red">Two</li>
</ul>
<div>Test</div>
</div>
Take the following steps (and experiment further) to understand how HTML elements can be manipulated with JavaScript code.
- Select the element with the class
output
. - Create another JavaScript object called
mainList
and select only theul
tag that is within theoutput
element. Update the ID of thatul
tag tomainList
. - Search for the
tagName
of eachdiv
, and output them into the console as an array. - Using a
for
loop, set the ID of each of thediv
tags toid
with a numeric value of the order they appear within output. Still within the loop, alternate the color of the contents of each...