-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJQuery-from-beg-to-advanced.html
365 lines (300 loc) · 13.6 KB
/
JQuery-from-beg-to-advanced.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!DOCTYPE html>
<html>
<head>
<title>JQuery- Beginning to Advanced</title>
</head>
<script src="js/jquery.js"></script>
<script>
$("document").ready(function(){
$("body").append("<h1>I LOVE JQuery!! </h1> ");
});
$("document").ready(function(){
// ON MOUSE CLICK AND LEAVE - EVENTS HANDLING
$("#textbox").on("click", function mouseOnClick(){
$("#textbox").html("<h1> You Clicked me</h1>");
});
$("#textbox").on("mouseleave", function mouseOnLeave(){
$("#textbox").html("<h1> Where are u goin ?? </h1>");
});
// HIDE AND SHOW ON CLICK
$("#show").on("click", function(){
$("#textbox2").show();
});
$("#hide").on("click", function(){
$("#textbox2").hide();
});
// HOVER EFFECTS
$(".textclass").hover(highClass);
function highClass(){
$(this).toggleClass("highlight");
}
// FADE IN/OUT on click
$("#fade-in").on("click", function(){
$(".fadebox").fadeIn(3000, function(){
alert("We are done with Fading IN");
});
});
$("#fade-out").on("click", function(){
$(".fadebox").fadeOut("fast", function(){
alert("We are done with Fading OUT");
});
});
// SLIDE Effect on CLICK
$("#slide-up").click(function(){
$(".slidebox").slideUp("3000", "linear");
});
$("#slide-down").click(function(){
$(".slidebox").slideDown("3000", "linear");
});
$("#slide-toggle").click(function(){
$(".slidebox").slideToggle("2000", function(){
alert("DONE!!!!");
});
});
// ANIMATION in JQuery
$("#grow").click(function(){
$("#animatebox").animate({width:"500px"}, 2000);
});
$("#move").click(function(){
$("#animatebox").animate({marginLeft: "200px"}, 2000);
});
$("#bigger").click(function(){
$("#animatebox").animate({fontSize: "35px", marginLeft: "250px", marginTop: "100px", width: "800px"}, 1000);
});
// SELECTORS
$("h5").css("border", "1px dotted red");
$("#blue").css("border", "2px solid blue");
$(".green").css("border", "3px solid green");
// FILTERS
$(".filter p:first").css("border", "1px solid blue");
$(".filter p:last").css("border", "1px solid blue");
$(".filter p:odd").css("background", "#c6c6c6");
$(".filter p:even").css("background", "#ff0000");
// ADVANCE SELECTORS
$("div > p.firstClass").css("border", "1px solid blue");
// CONTENT CREATION
$(".content1 p:first-child").css("fontSize", "24px" );
$(".content1 p:parent").css("background", "pink" );
$(".content1 p:last-of-type").css("fontFamily", "cursive" );
$(".content1 p:contains('sanchit')").css("background", "red" );
$(".content2 p:nth-child(2)").css("background", "blue" );
$(".content2 p#firstpara").text("This was replaced");
var newText = $(".content2 p:second");
$(".content2 p#last").html(newText);
});
$("document").ready(function(){
// INSERT CONTENT
$("#append").click(function(){
$(".insert p:first").append("HELLO!!! I'm here appending the content at the end..!!");
});
$("#prepend").click(function(){
$(".insert p:last").prepend("HELLO!!! I'm here prepending the content in begenning..!!");
});
// MODIFYING CONTENT
$("#modify p:first").wrap("<div class='colorBox'>");
$("#modify p:last").replaceWith("<div>I'm replaced by someone</div>");
// MODIFY CSS
$("#add-class").click(function(){
$(".modify-css p:first").addClass('color');
});
$("#remove-class").click(function(){
$(".modify-css p:first").removeClass('color');
});
$("#toggle-class").click(function(){
$(".modify-css p:first").toggleClass('color');
});
$("#fontsize").click(function(){
$(".modify-css p:last").css("font-size", "+=1px");
});
});
</script>
<style type="text/css">
#textbox{
background: blue;
width: 300px;
height: 200px;
}
.highlight{
background: red;
}
#animatebox{
background-color: #ccc;
width: 200px;
height: 400px;
position: absolute;
margin-top: 70px;
}
.colorBox{
color: #cccccc;
}
.color{
color:skyblue;
}
</style>
<body>
<div id="textbox">
</div>
<br><br>
<!-- SHOW/HIDE Effects -->
<a href="#show" id="show">Click to Show</a> || <a href="#hide" id="hide">CLick to hide</a>
<div id="textbox2" style="display: none;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<!-- HOVER EFFECTS -->
<p class="textclass">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<br><br>
<!-- FADE IN/OUT effects on click -->
<a href="#fade-in" id="fade-in">FADE IN</a> || <a href="#fade-out" id="fade-out">FADE OUT</a>
<div class="fadebox" style="display: none;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laboru.</p>
</div>
<br><br>
<!-- SLIDE Operations -->
<a href="#slide-up" id="slide-up">SLIDE UP</a> || <a href="#slide-down" id="slide-down">SLIDE DOWN</a> || <a href="#slide-toggle" id="slide-toggle">SLIDE TOGGLE</a>
<div class="slidebox">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<br><br>
<!-- ANIMATIONS in JQuery -->
<a href="#grow" id="grow">GROW</a> || <a href="#move" id="move">MOVE</a> || <a href="#bigger" id="bigger">BIGGER</a>
<div id="animatebox">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<br>
</div>
<br><br>
<!-- SELCTORS -->
<div>
<h5>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.lo</h5>
<h5 id="blue">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.lo</h5>
<h5 class="green">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.lo</h5>
</div>
<!-- FILTERS -->
<div class="filter">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<!-- Advance SELECTORS -->
<br><br><br>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<div>
<p class="firstClass">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<!-- Creating Content -->
<h4>CONTENT1</h4>
<div class="content1">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut sanchit et dolore magna aliqua. </p>
</div>
<br>
<h4>CONTENT2</h4>
<div class="content2">
<p id="firstpara"> 11111 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p> 22222 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>33333 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<!-- INSERTING CONTENT -->
<br><br>
<a href="#append" id="append">APPEND</a>
<a href="#prepend" id="prepend">PREPEND</a>
<div class="insert">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<br><br>
<!-- MODIFYING CONTENT -->
<div id="modify">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<!-- MODIFYING CSS -->
<div class="modify-css">
<br>
<a href="#add-class" id="add-class">ADD CSS</a> || <a href="#remove-class" id="remove-class">REMOVE CSS</a> || <a href="#toggle-class" id="toggle-class">TOGGLE CSS</a> || <a href="#fontsize" id="fontsize">CHANGE SIZE</a>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</body>
</html>