Skip to content

Commit 560bb69

Browse files
author
Josh Hill
committed
Flesh out exercise 1 instructions
1 parent 0a4a455 commit 560bb69

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

js/lesson3/tutorial.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,27 @@ function addToList(item) {
183183

184184
}
185185
```
186-
In the `index.html` file, we already have an `<ol>` component, so we want to add each new item, as a list item. We can do that by constructing the html we need `"<li>" + item + "</li>"` and adding it to the list using `append()`.
186+
In the `index.html` file there is an empty list, `<ol id="items">`, and we're going to add list items to it.
187187

188-
We can get the ordered list using the element tag and the id `$("ol#items")`
188+
Target the empty list using its html tag and id: `$("ol#items")`.
189189

190-
Try running the function you've just written from the inspector
190+
Then construct the html for a new list item `"<li>" + item + "</li>"` and add it to the end of the list using jQuery's `append()` method.
191+
192+
Try running the function you've just written from the browser console.
191193

192194
```js
193195
addToList("build a website");
194196
```
195197

196-
Now that you can successfully add items to the list, bind the function to the button with the id `#add-to-list`. To get the text from the input field, you can use `$("#item").val()`.
198+
Now that you can successfully add items to the list, write an event handler to listen for the `click` event on the button. Tip: the button's id is `#add-to-list`.
199+
200+
Then use jQuery's `val()` method to get the text from the input field and run your `addToList()` function with the input field text as the argument from the event handler. Tip: the input field's id is `#item`.
197201

198202
###Bonus
199-
After adding the item to the list
203+
After adding the item to the list:
200204

201-
1. Empty the text field
202-
2. Use `focus()` to place the cursor back to the text field
205+
1. Empty the text field after adding the item to the list.
206+
2. Use jQuery's `focus()` method to place the cursor back in the text field after clicking the button.
203207

204208
###Label items
205209

0 commit comments

Comments
 (0)