Skip to content

Commit bd011d0

Browse files
committed
readme
1 parent 32e9013 commit bd011d0

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,43 @@
33
## Objectives
44

55
+ Write inline jQuery to modify HTML
6-
+ Explain how jQuery modifies HTML
6+
+ Explain how jQuery modifies HTML
7+
8+
## Inline jQuery
9+
10+
We're going to use jQuery to add some text to our HTML page.
11+
12+
### Include jQuery Link
13+
14+
In order to start writing jQuery, we need to include the library in our HTML. You'll want to copy the code below and paste it `html/index.html` in between your head tags. This script tag links our HTML file to the jQuery library.
15+
16+
```html
17+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
18+
```
19+
20+
### Adding Text
21+
22+
Go ahead and open `html/index.html` in the browser. You should see a really boring looking website with the text `yo yo yo yo yo yo yo`.
23+
24+
We want to add the text `hey hey hey hey!!!!!` to end of our paragraph.
25+
26+
At the bottom of `index.html`, right before the closing `body` tag, we'll want to add an opening and a closing `script` tag:
27+
28+
```html
29+
<script>
30+
</script>
31+
```
32+
33+
Between these tags is where we want to write our inline jQuery. The script tags need to be at the bottom of the page because the code we're going to write it dependent on the `p` tag being already loaded in the browser. Our jQuery will error if there isn't a `p` tag to add text to.
34+
35+
And now, in between the script tags, add the following code:
36+
37+
```js
38+
$("#yo").append("hey hey hey hey!!!!!");
39+
```
40+
41+
Save the changes to `html/index.html` and reload in the browser. You should see `yo yo yo yo yo yo yo hey hey hey hey!!!!!` on the page!!
42+
43+
The `$` tells our browser that we're using jQuery. The `("#yo")` is our jQuery selector -- we're selecting the HTml element with the ID `yo`. We're then using the jQuery `append` function, which adds text to an HTML element, and we're passing in `"hey hey hey hey!!!!!"` which is the text we want to add.
44+
45+
Don't worry too much about the mechanics of these selectors and functions, we'll go over those in way more detail. Just notice that the text appeared on the screen!

html/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<head>
3+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
4+
</head>
5+
<body>
6+
7+
<p id="yo"> yo yo yo yo yo yo yo </p>
8+
<script>
9+
$("#yo").append("hey hey hey hey!!!!!");
10+
</script>
11+
12+
</body>

0 commit comments

Comments
 (0)