-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery examples.txt
More file actions
1130 lines (1110 loc) · 26.8 KB
/
Copy pathjquery examples.txt
File metadata and controls
1130 lines (1110 loc) · 26.8 KB
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--------------------------------------------------
variables-
var $target =$('#tr');
$target.fadeOut('fast');
------------------------------------------------------------------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();
});
});
</script>
.......
<p>This is another paragraph.</p>
<button>Click me</button>
----------------------------------------------
<script>
$( document ).click(function() {
$( "#toggle" ).toggle( "bounce", { times: 3 }, "slow" );
});
</script>
.........
<p>Click anywhere to toggle the box.</p>
<div id="toggle"></div>
------------------------------------------
<script>
$(document).ready(function(){
$( ".third-item" ).next().css( "background-color", "red" );
});
</script>
......
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li class="third-item">list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
</ul>
----------------------------------------
<script>
$(document).ready(function(){
$("#q").click(function(){
$("p").css("background-color", "red");
});
});
</script>
.......
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button id="q">Add a class name to the first p element</button>
------------------------------------------
<script>
$(document).ready(function(){
$("p:nth-child(3)").css("background-color", "yellow");
});
</script>
..........
<body>
<h1>This is a heading in body</h1>
<p>The first paragraph in body.</p>
<p>The second paragraph in body (and the 3rd child element in body).</p>
<div style="border:1px solid;">
<span>This is a span element in div</span>
<p>The first paragraph in div.</p>
<p>The second paragraph in another div (and the 3rd child element in this div).</p>
<p>The last paragraph in div.</p>
</div><br>
<div style="border:1px solid;">
<p>The first paragraph in another div.</p>
<p>The second paragraph in another div.</p>
<p>The last paragraph in another div (and the 3rd child element in this div).</p>
</div>
<p>The last paragraph in body.</p>
</body>
-----------------------------------------
p:nth-child(3)/p:odd()/p:even()
--------------------------------------------
<script>
$(document).ready(function(){
$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
});
</script>
............
<p id="test">This is some <b>bold</b> text in a paragraph.</p>
<button id="btn1">Show Text</button>
<button id="btn2">Show HTML</button>
-----------------------------------------------
<script>
$(document).ready(function(){
$(function(){
var val=$("p").html();
alert(val);
var val=$("p").text();
alert(val);
});
});
</script>
..........
<p>jquery is <b>fun</b></p>
-------------------------------------------------
<script>
$(document).ready(function(){
$("#q").click(function(){
$("#t").html("<em>heeeeyyyyyy</em>");
});
});
</script>
............
<p>This is a paragraph.</p>
<p id="t">This is another paragraph.</p>
<button id="q">Add a class name to the first p element</button>
----------------------------------------------------
<script>
$( document ).click(function() {
$( "#toggle" ).effect( "shake" );
});
</script>
........
<p>Click anywhere to shake the box.</p>
<div id="toggle"></div>
--------------------------------------------------
<script>
$(document).ready(function(){
$("#q").click(function(){
$("p:first").addClass("intro");
});
$("#w").click(function(){
$("p:first").removeClass("intro");
});
});
</script>
..........
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button id="q">Add a class name to the first p element</button>
<button id="w">remove</button>
......
<style>
.intro {
font-size: 150%;
color: red;
}
</style>
---------------------------------------------
<script>
$(document).ready(function(){
$("#q").click(function(){
$("#t").prop("disabled",true);
});
});
</script>
...........
<button id="q">Add a class name to the first p element</button>
<button id="t">remove</button>
-----------------------------------------
<script>
$(document).ready(function(){
$("#q").click(function(){
$("#t").remove();
});
});
</script>
........
<p>This is a paragraph.</p>
<p id="t">This is another paragraph.</p>
<button id="q">Add a class name to the first p element</button>
-----------------------------------------
<script>
$(document).ready(function(){
$("#q").click(function(){
$("#t").empty();
});
});
</script>
........
<p>This is a paragraph.</p>
<p id="t">This is another paragraph.</p>
<button id="q">Add a class name to the first p element</button>
-----------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("<span>Hello World!</span>").appendTo("p");
});
});
</script>
........
<button>Insert span element at the end of each p element</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
------------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("<span>Hello World! </span>").prependTo("p");
});
});
</script>
..........
<button>Insert span element at the beginning of each p element</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
--------------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").clone().appendTo("body");
});
});
</script>
...........
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Clone all p elements, and append them to the body element</button>
----------------------------------------
<script>
$(document).ready(function(){
$('div').click(function() {
$('div').fadeOut('slow'); // $('div').fadeOut(1000);
});
});
</script>
........
<div>drsferfae</div>
........
div{
height:100px;
width:100px;
border:4px solid black;}
---------------------------------
<script>
$(document).ready(function(){
$('div').dblclick(function(){
$('div').fadeOut('fast');
});
});
</script>
.........
<div>iji</div>
........
<style>
div{
height:100px;
width:100px;
border:4px solid black;}
</style>
------------------------------------------------
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("p").slideUp();
});
$(".btn2").click(function(){
$("p").slideDown();
});
});
</script>
........
<p>This is a paragraph.</p>
<button class="btn1">Slide up</button>
<button class="btn2">Slide down</button>
----------------------------------
<script>
$(document).ready(function(){
$('div').mouseenter(function(){
$('div').hide();
});
});
</script>
........
<div>drsferfae</div>
.......
<style>
div{
height:100px;
width:100px;
border:4px solid black;}
</style>
--------------------------------
<script>
$(document).ready(function(){
$('div').mouseleave(function(){
$('div').fadeTo('fast',0.5);
});
});
</script>
.........
<div>drsferfae</div>
.......
<style>
div{
height:100px;
width:100px;
border:4px solid black;}
</style>
-------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("#w3s").attr("href", "https://www.w3schools.com/jquery");
});
});
</script>
..........
<p><a href="https://www.w3schools.com" id="w3s">W3Schools.com</a></p>
<button>Change href Value</button>
-----------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").removeAttr("style");
});
});
</script>
..........
<p style="font-size:120%;color:red">This is a paragraph.</p>
<p style="font-weight:bold;color:blue">This is another paragraph.</p>
<button>Remove the style attribute from all p elements</button>
-----------------------------------
<script>
$(document).ready(function(){
$(function(){
$("#demo").before("<i>Some title</i>");
$("#demo").after("<b>welcome</b>");
$("#test").text("hello");
});
});
</script>
..........
<p id="demo">hI</P>
<p id="test">bj</p>
-----------------------------------
<script>
$(document).ready(function(){
$("p").hover(function(){
$(this).css("background-color", "yellow");
}, function(){
$(this).css("background-color", "pink");
});
});
</script>
............
<p>Hover the mouse pointer over this paragraph.</p>
---------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").toggleClass("main");
});
});
</script>
..........
<style>
.main {
font-size: 120%;
color: red;
}
</style>
.........
<button>Toggle class "main" for p elements</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p><b>Note:</b> Click the button more than once to see the toggle effect.</p>
-------------------------------------------
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("p").append(" <b>Appended text</b>.");
});
$("#btn2").click(function(){
$("ol").append("<li>Appended item</li>");
});
});
</script>
........
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
<button id="btn1">Append text</button>
<button id="btn2">Append list item</button>
----------------------------------------------
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("p").prepend("<b>Prepended text</b>. ");
});
$("#btn2").click(function(){
$("ol").prepend("<li>Prepended item</li>");
});
});
</script>
..........
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
<button id="btn1">Append text</button>
<button id="btn2">Append list item</button>
-----------------------------------------------
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
........
<style>
#panel, #flip {
padding: 5px;
text-align: center;
background-color: #e5eecc;
border: solid 1px #c3c3c3;
}
#panel {
padding: 50px;
display: none;
}
</style>
........
<div id="flip">Click to slide the panel down or up</div>
<div id="panel">Hello world!</div>
-------------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("li").length);
});
});
</script>
.........
<button>Alert the number of li elements</button>
<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
------------------------------------------------
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("p").find("span").addClass("selected");
});
</script>
............
<style>
.selected { color:red; }
</style>
...........
<div>
<p><span>Hello</span>, how are you?</p>
<p>Me? I'm <span>good</span>.</p>
</div>
-----------------------------------------
<script>
$("button").click(function(){
$( "div" ).find( "#span1" ).addClass("highlight").end()
.find("#span2") .css("background-color", "red").end()
.animate({height: 250});
});
</script>
................
<div>div
<span id="span1">Span 1</span>
<span id="span2">Span2</span>
</div>
------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("li").each(function(){
alert($(this).text())
});
});
});
</script>
..............
<button>Alert the value of each list item</button>
<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
---------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
var $x = $("div");
$x.prop("color", "FF0000");
$x.append("The color property has the following value: " + $x.prop("color"));
$x.removeProp("color");
$x.append("<br>Now the color property has the following value: " + $x.prop("color"));
});
});
</script>
.............
<button>Add and remove a property</button><br><br>
<div></div>
-------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("<h2>Hello world!</h2>").replaceAll("p");
});
});
</script>
........
<button>Replace all p elements with h2 elements</button><br>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
------------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("p:first").replaceWith("Hello world!");
});
});
</script>
........
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Replace the first p element with new text</button>
-----------------------------------
<script>
$(document).ready(function(){
$("button").click(function(){
$("input:text").val("Glenn Quagmire");
});
});
</script>
........
<p>Name: <input type="text" name="user"></p>
<button>Set the value of the input field</button>
----------------------------------
<script>
$(document).ready(function(){
$("h1").add("p").add("span").css("background-color", "yellow");
});
</script>
.......
<h1>Welcome</h1>
<p>A p element.</p>
<p>Another p element.</p>
<span>A span element.</span>
<span>A span element.</span><br><br>
<div>This example adds the same css style for both p and span elements, as the existing h1 element.</div>
------------------------------------
<script>
$(document).ready(function(){
$('p.a').nextAll().addBack()
.css('background-color', 'yellow');
});
</script>
......
<p class="a">A</p>
<p>B</p>
<p>C</p>
--------------------------------------
<script>
$(document).ready(function(){
$("div").children(".selected").addClass("blue");
});
</script>
........
<div>
<span>Hello</span>
<p class = "selected">Hello Again</p>
<div class = "selected">And Again</div>
<p class = "biggest">And One Last Time</p>
</div>
.........
<style>
.blue { color:blue; }
</style>
--------------------------------------
script>
$(document).ready(function(){
$(document).bind("click", function (e) {
$(e.target).closest("li").toggleClass("highlight");
});
});
</script>
..........
<div>
<p>Click any item below to see the result:</p>
<ul>
<li class = "top">list item 1</li>
<li class = "top">list item 2</li>
<li class = "middle">list item 3</li>
<li class = "middle">list item 4</li>
<li class = "bottom">list item 5</li>
<li class = "bottom">list item 6</li>
</ul>
</div>
........
<style>
.highlight { color:red; background: yellow;}
</style>
------------------------------------------
<script>
$(document).ready(function(){
$("p:eq(3)").css("background-color","yellow");
});
</script>
.........
<h1>Welcome to My Homepage</h1>
<p class="intro">My name is Donald.</p>
<p>I live in Duckburg.</p>
<p>My best friend is Mickey.</p>
<p>Who is your favourite:</p>
<ul id="choose">
<li>Goofy</li>
<li>Mickey</li>
<li>Pluto</li>
</ul>
------------------------------------------
<script>
$(document).ready(function(){
$("p:first").css("background-color", "yellow");
});
</script>
.........
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the last paragraph.</p>
----------------------------------------
<script>
$(document).ready(function(){
$("p:last").css("background-color", "yellow");
});
</script>
.........
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the last paragraph.</p>
--------------------------------------
<script>
$( "p" ).parent( ".selected" ).css( "background", "yellow" );
</script>
......
<div class="selected"><p>Hello Again</p></div>
--------------------------------------
<script>
var $curr = $( "#start" );
$curr.css( "background", "#f99" );
$( "button" ).click(function() {
$curr = $curr.prev();
$( "div" ).css( "background", "" );
$curr.css( "background", "#f99" );
});
</script>
.............
<div></div>
<div></div>
<div><span>has child</span></div>
<div></div>
<div></div>
<div></div>
<div id="start"></div>
<div></div>
<p><button>Go to Prev</button></p>
.........
<style>
div {
width: 40px;
height: 40px;
margin: 10px;
float: left;
border: 2px blue solid;
padding: 2px;
}
span {
font-size: 14px;
}
p {
clear: left;
margin: 10px;
}
</style>
---------------------------------------
<ul>
<li>One</li>
<li>Two</li>
<li class="hilite">Three</li>
<li>Four</li>
</ul>
<ul>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
</ul>
<ul>
<li>Eight</li>
<li class="hilite">Nine</li>
<li>Ten</li>
<li class="hilite">Eleven</li>
</ul>
<p>Unique siblings: <b></b></p>
.........
<script>
var len = $( ".hilite" ).siblings()
.css( "color", "red" )
.length;
$( "b" ).text( len );
</script>
--------------------------------------------
<script>
$(document).ready(function(){
$("p").slice(1).css("background-color", "yellow");
});
</script>
.........
<h1>Welcome to My Homepage</h1>
<p>My name is Donald (index 0).</p>
<p>Donald Duck (index 1).</p>
<p>I live in Duckburg (index 2).</p>
<p>My best friend is Mickey (index 3).</p>
-----------------------------------------------
<script>
$("p").filter(".class1").css("border", "1px dotted red");
</script>
..............
<p class="class">Delhi</p>
<p class="class1">Hyderabad</p>
<p class="class2">Mumbai</p>
-----------------------------------------------
<script>
$("h1").css("background", "#c0c0c0").height("200px");
</script>
..........
<h1>This is H1</h1>
<h2>This is H2</h2>
----------------------------------------------
<script>
$("h1").css("background", "#c0c0c0").width("200px");
</script>
..........
<h1>This is H1</h1>
<h2>This is H2</h2>
----------------------------------------------
<script>
$("h1").insertAfter("#div3");
</script>
.........
<div>
<h1>This is H1</h1>
<p id="div1">This is DIV1 in P tag.</p>
<p id="div2">This is DIV2 in P tag.</p>
<p id="div3">This is DIV3 in P tag.</p>
<p id="div4">This is DIV4 in P tag.</p>
</div>
----------------------------------------------
<script>
$("h1").insertBefore("#div3");
</script>
.........
<div>
<h1>This is H1</h1>
<p id="div1">This is DIV1 in P tag.</p>
<p id="div2">This is DIV2 in P tag.</p>
<p id="div3">This is DIV3 in P tag.</p>
<p id="div4">This is DIV4 in P tag.</p>
</div>
----------------------------------------------
<p id="divScroll">This is the main text of the Page, This is the sub content of the page and also it includes many subtitles. These all are done by the developers of techfunda.com and dotnetfunda.com and you can find the many intresting things in the techfunda.com and also you can be able to learn the all the technologies at free of cost with out going any where. The main theme of the techfunda.com is to provide the free tutorials to the people who want to survive in this competetive world.</p>
<p></p>
........
<style>
#divScroll{
color:green;
padding:10px;
margin:10px;
border:2px solid;
height:600px;
width:800px;
}
</style>
.............
<script>
$("#divScroll").scrollLeft("100"); // $("#divScroll").scrollTop("100");
</script>
--------------------------------------------------
<script>
$("#txtBlur").blur(function () {
alert("blur handler called");
});
</script>
...............
<form>
<input id="txtBlur" type="text" value="TechFunda">
<input type="text" value="DotNetFunda">
</form>
------------------------------------------------
<select id="dropChange">
<option value="TechFunda" selected="selected">Select</option>
<option value="SheoNarayan">Sheo Narayan</option>
<option value="DotNetFunda">DotNetFunda</option>
<option value="ITFunda">IT Funda</option>
<option value="MyFunda">My Funda</option>
<option value="KidsFunda">KidsFunda</option>
<option value="FarmingFunda">FarmingFunda</option>
<option value="FundooVideo">FundooVideo</option>
</select>
..........
<script>
$("#dropChange").change(function () {
alert("This is the OutPut of .change() in jQuery");
});
</script>
--------------------------------------------
<form>
<input type="button" id="btnAction" value="Constatnt" style="color:blue;background-color:yellow"/>
<input type="button" name="btn" id="btnBindAction" value="Bind"/>
<input type="button" name="btn" id="btnUnbindAction" value="UnBind"/>
</form>
..................
<script>
function bindAction() {
alert("I am active !");
}
$("#btnBindAction").click(function () {
$("#btnAction").bind('click', bindAction).val("Click Now");
});
$("#btnUnbindAction").click(function () {
$("#btnAction").unbind('click', bindAction).val("Simple Button");
});
</script>
----------------------------------------------
input type="button" id="btnAction" value="Constatnt" style="color:blue;background-color:yellow"/>
<input type="button" name="btn" id="btnBindAction" value="Bind"/>
<input type="button" name="btn" id="btnUnbindAction" value="UnBind"/>
</form>
..................
<script>
function bindAction() {
alert("I am active !");
}
$("#btnBindAction").click(function () {
$("#btnAction").bind('mouseenter click', bindAction).val("Mouse hover Now and then click");
});
$("#btnUnbindAction").click(function () {
$("#btnAction").unbind('mouseenter click', bindAction).val("Simple button");
});
</script>
------------------------------------------------
<div id="pEventXEventY">This page is event.pageX and event.pageY page, you can check by moving the curser on the color surrounded area. </div>
..................
<script>
$("#pEventXEventY").bind("mousemove", function (e) {
$(this).text("pageX: " + e.pageX + " pageY: " + e.pageY);
});
</script>
--------------------------------------------------
<img src="idonotknow.jpg" id="imgError" />
.................
<script>
$("#imgError").error(function () {
alert("missing image");
});
</script>
------------------------------------------------
<div id="divEventTarget" style="background:#dedede;width:300px;height:100px;">
<br />
<p>event.target demo <br />
<span>
this is span
</span>
<br />- This is the p
</p>
<br />
</div>
<script>
$("#divEventTarget").click(function (e) {
alert(e.target.nodeName);
});
</script>
-------------------------------------------
<form>
User Id : <input type="text" name="user" id="txtFocus"/>
Password : <input type="password" name="password" id="txtFocus1"/>
</form>
<script>
$("#txtFocus, #txtFocus1").focus(function () {
alert("got focus");
});
</script>
------------------------------------------------
<script>
$(document).ready(function(){
$( "p" ).last().addClass( "selected" );
});
</script>
.....
<style>
p {
margin: 8px;
font-size: 16px;
}
.selected {
color: blue;
}
.highlight {
background: yellow;
}
</style>
......
<p>Hello</p>
<p>and</p>
<p>Goodbye</p>
-----------------------------------------------
functions in jquery-
<script>
$( "div" ).addClass(function( index, currentClass ) {
var addedClass;
if ( currentClass === "red" ) {
addedClass = "green";
$( "p" ).text( "There is one green div" );
}
return addedClass;
});
</script>
.....
<div>This div should be white</div>
<div class="red">This div will be green because it now has the "green" and "red" classes.
It would be red if the addClass function failed.</div>
<div>This div should be white</div>
<p>There are zero green divs</p>
......
<style>
div {
background: white;
}
.red {
background: red;
}
.red.green {
background: green;
}
</style>
-----------------------------------------------------------
<script>
$(document).ready(function(){
$( "p" )
.on( "mouseenter", function() {
$( this ).css({
"background-color": "yellow",
"font-weight": "bolder"
});
})
.on( "mouseleave", function() {
var styles = {
backgroundColor : "#ddd",
fontWeight: ""
};
$( this ).css( styles );
});
});
</script>
.....
<p>Move the mouse over a paragraph.</p>
<p>Like this one or the one above.</p>
.....
<style>
p {
color: green;
}
</style>