2. Working with JavaScript
Activity 2.01: Adding and Modifying an Item to/in the To-Do List
Solution
- Create the HTML file yourself and paste in the HTML code to get started:
Figure 2.28: The initial to-do list's appearance
- The first thing we need to do is assign an ID to our list in order to identify it via code. To do this, add an
id
attribute to theol
element and give it a value oftodo-list
. With that complete, we can then address this element directly with JavaScript:<ol id="todo-list">
- Using a bit of JavaScript code, we can now create a new variable named
parentContainer
. This will refer to the ordered list container element that holds all of our list items. We'll use the ID we assigned in the previous step to address this element directly via the use of thegetElementById()
method:var parentContainer = document.getElementById('todo-list');
- Create a new HTML
<li>
list item element via JavaScript. Right now,...