You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make a note of this. Wrapping your event listeners and other code within this make's sure they are executed only after all the DOM elements are loaded and ready. You should **always** use it or else your bindings won't work and the functions will run when you are loading the page.
152
+
Make a note of this. Wrapping your event listeners and other code within this makes sure they are executed only after all the DOM elements are loaded and ready. You should **always** use it or else your bindings won't work and the functions will run before all elements on the page have loaded. So it might try to listen for events on elements that don't even exist yet and then you'll get lots of errors.
152
153
153
154
#Exercise 1: Build a wish list
154
155
155
156
Using jQuery and JavaScript functions, we will build a small todo list.
156
157
157
-
Download the files required to begin working through the example [here](https://gist.github.com/despo/309f684b7a6e002aaf1f) or alternatively checkout with git.
158
+
If you haven't yet, download the files required to begin working through the example [here](https://gist.github.com/despo/309f684b7a6e002aaf1f) or alternatively checkout with git.
@@ -165,7 +166,7 @@ Move the files under your Github page folder, in a new directory `wishlist`. Als
165
166
```bash
166
167
git commit -m "message"
167
168
```
168
-
169
+
If you don't know how to use git yet, just ignore the above for now or [look at our git tutorial](http://tutorials.codebar.io/version-control/introduction/tutorial.html).
169
170
170
171
##Functionality
171
172
- add wishes to the list by clicking the Add button
@@ -205,9 +206,11 @@ After adding the item to the list:
205
206
1. Empty the text field after adding the item to the list.
206
207
2. Use jQuery's `focus()` method to place the cursor back in the text field after clicking the button.
207
208
209
+
If you don't know how to use the focus() method, try searching for it in the [jQuery documentation](http://api.jquery.com/). There are some code examples illustrating how to use it.
210
+
208
211
###Label items
209
212
210
-
To label items, update the html of the list item being added to the list, so it includes a label.
213
+
To label items as "pending" or "done", add the below html code to the html for the new list item that you wrote at the beginning of the tutorial.
211
214
212
215
`<span class='label pending'>Pending</span>`
213
216
@@ -221,6 +224,8 @@ When we click on the Pending label, we want to set items to complete. We will do
221
224
222
225
> Use `$(this)` to access the element that the event was triggered from.
223
226
227
+
Let's go through this step by step.
228
+
224
229
Try this in the console:
225
230
226
231
First of all, bind a **click** event to the span we've added using its class with the `on()` function. As `<li>` is the parent node of the <span> element, we can access it using `parent()` (which is equivalent to `parentNode`
@@ -230,10 +235,11 @@ that we've used in the previous lesson).
230
235
var parent_node =$(this).parent();
231
236
```
232
237
233
-
> Use `attr()` to set the class attribute to `completed`or alternatively `addClass()`
238
+
> Use `attr()`or `addClass()`to set the class attribute to `completed`
234
239
235
240
> Use `remove()` to remove an element from the DOM
236
241
242
+
When you now click on the red label "pending", it should change to the green label "completed".
237
243
238
244
###Show the total task count
239
245
@@ -274,7 +280,7 @@ Have a look at our [**Wish List**](../../examples/wishlist/index.html).
274
280
https://gist.github.com/ab21d29aa1ea8fbbbb0e.git
275
281
```
276
282
277
-
Move the files under your Github page folder, in a directory colorpicker.
283
+
if you're using git, move the files under your Github page folder, in a directory colorpicker.
278
284
Don't forget to commit each task you complete! That way it will be easier to retrace your steps if something goes wrong!
0 commit comments