Skip to content

Commit 10e9603

Browse files
adding more detailed explanations and changing a few sentences for clarity
1 parent fee43a6 commit 10e9603

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

js/lesson3/tutorial.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ $('#container').append("<div>I love jQuery!</div>")
9090

9191
You can also use `replaceWith()` to substitute an element entirely with some new content.
9292

93-
Try this out in your browser.
93+
Open the index.html of the files provided in your browser and try this out in the JavaScript console:
9494

9595
```js
9696
$('#container').replaceWith("<div>I love jQuery!</div>")
@@ -115,6 +115,7 @@ $(document).on('click','.done', function() {
115115
alert("Click event");
116116
});
117117
```
118+
This function makes a JavaScript alert pop up when a user clicks on any element which has the class ".done".
118119

119120
Although these two examples do the same thing there are some differences.
120121

@@ -148,13 +149,13 @@ $(document).ready(function() {
148149
});
149150
```
150151

151-
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.
152153

153154
#Exercise 1: Build a wish list
154155

155156
Using jQuery and JavaScript functions, we will build a small todo list.
156157

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.
158159

159160
```bash
160161
git clone https://gist.github.com/309f684b7a6e002aaf1f.git wishlist
@@ -165,7 +166,7 @@ Move the files under your Github page folder, in a new directory `wishlist`. Als
165166
```bash
166167
git commit -m "message"
167168
```
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).
169170

170171
##Functionality
171172
- add wishes to the list by clicking the Add button
@@ -205,9 +206,11 @@ After adding the item to the list:
205206
1. Empty the text field after adding the item to the list.
206207
2. Use jQuery's `focus()` method to place the cursor back in the text field after clicking the button.
207208

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+
208211
###Label items
209212

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.
211214

212215
`<span class='label pending'>Pending</span>`
213216

@@ -221,6 +224,8 @@ When we click on the Pending label, we want to set items to complete. We will do
221224

222225
> Use `$(this)` to access the element that the event was triggered from.
223226
227+
Let's go through this step by step.
228+
224229
Try this in the console:
225230

226231
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).
230235
var parent_node = $(this).parent();
231236
```
232237

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`
234239
235240
> Use `remove()` to remove an element from the DOM
236241
242+
When you now click on the red label "pending", it should change to the green label "completed".
237243

238244
###Show the total task count
239245

@@ -274,7 +280,7 @@ Have a look at our [**Wish List**](../../examples/wishlist/index.html).
274280
https://gist.github.com/ab21d29aa1ea8fbbbb0e.git
275281
```
276282

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.
278284
Don't forget to commit each task you complete! That way it will be easier to retrace your steps if something goes wrong!
279285

280286
##Functionality

0 commit comments

Comments
 (0)