Labs
-
Create an HTML file named
traverse.htmland a JavaScript file namedtraverse.js. -
Write a well-formed HTML document in
traverse.htmland add an<h1>that says 'Hello World'. -
Import your
traverse.jsfile into yourtraverse.htmlfile using<script src=''></script> -
Add an unordered list of 5 list items to the HTML (don't put any text between the
<li>s) -
Next to each of the list items, place a button with the text 'Edit' on it.
<li></li><button class="edit">Edit</button> -
In your
traverse.jsfile, assign a 'click' event listener to each of your 'Edit' buttons. Do not create 5 separate callback function, rather create 1 that works for all 5 buttons. -
When the 'Edit' button is clicked, it should use a
promptto prompt the user for a new value to place in that list item. -
When the user enters a new value for the list item, select the list item and change its
textContentto match the entered text.Hint: How are the buttons ordered in terms of a parent/child/sibling relationship?
-
Add another button next to each of the 'Edit' buttons, which will have 'Clear' on it.
-
Assign event listeners to each of the 'Clear' buttons that will use
confirmto confirm that the user wishes to delete the item. If the user affirms the deletion, usetextContentto clear the corresponding list item's value. Otherwise, don't change the value.<li>Stuff</li><button class="edit">Edit</button><button class="clear">Clear</button>Hint: the list item is the second previous sibling of whichever clear button has been clicked.