@@ -35,9 +35,7 @@ many JavaScript programmers wrap their code in an `onload` function:
35
35
36
36
```
37
37
window.onload = function() {
38
-
39
38
alert("welcome");
40
-
41
39
}
42
40
```
43
41
@@ -47,23 +45,17 @@ known as the [ ready event ](http://api.jquery.com/ready):
47
45
48
46
```
49
47
$( document ).ready( function() {
50
-
51
48
// Your code here
52
-
53
49
});
54
50
```
55
51
56
52
For example, inside the ` ready ` event, you can add a click handler to the link:
57
53
58
54
```
59
55
$( document ).ready(function() {
60
-
61
56
$("a").click(function( event ) {
62
-
63
57
alert("Thanks for visiting!");
64
-
65
58
});
66
-
67
59
});
68
60
```
69
61
@@ -76,15 +68,10 @@ you can prevent the default behavior by calling `event.preventDefault()` in the
76
68
77
69
```
78
70
$( document ).ready(function() {
79
-
80
71
$("a").click(function( event ) {
81
-
82
72
alert("As you can see, the link no longer took you to jquery.com");
83
-
84
73
event.preventDefault();
85
-
86
74
});
87
-
88
75
});
89
76
```
90
77
@@ -106,19 +93,12 @@ and load it on the page with a `<script>` element's `src` attribute.
106
93
<a href="http://jquery.com/">jQuery</a>
107
94
<script src="jquery.js"></script>
108
95
<script>
109
-
110
96
$( document ).ready(function() {
111
-
112
97
$("a").click(function( event ) {
113
-
114
98
alert("The link will no longer take you to jquery.com");
115
-
116
99
event.preventDefault();
117
-
118
100
});
119
-
120
101
});
121
-
122
102
</script>
123
103
</body>
124
104
</html>
@@ -162,11 +142,8 @@ For example, if you create a click handler of:
162
142
163
143
```
164
144
$("a").click(function( event ){
165
-
166
145
event.preventDefault();
167
-
168
146
$( this ).hide("slow");
169
-
170
147
});
171
148
```
172
149
@@ -217,9 +194,7 @@ Note the use of `function() {`. The anonymous function does exactly one thing:
217
194
218
195
```
219
196
$.get( "myhtmlpage.html", function() {
220
-
221
197
myCallBack( param1, param2 );
222
-
223
198
});
224
199
```
225
200
0 commit comments