-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathPart2_Events.js
73 lines (56 loc) · 1.43 KB
/
Part2_Events.js
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
// jQuery makes it easy to interact with the DOM!
// List of all possible events!
// https://api.jquery.com/category/events/
//////////////
// CLICKS ///
////////////
// On Click
$('h1').click(function(){
console.log("There was a click!");
})
// Click on multiple elements
$('li').click(function() {
console.log("Click on any li !");
})
// Using This with jQuery
$('h3').click(function() {
$(this).text("I was changed!");
})
/////////////////
// KEYPRESS ////
///////////////
// Using This with jQuery
$('input').eq(0).keypress(function() {
$('h3').toggleClass("turnRed");
})
// We can use this event object, that has a ton of information!
$('input').eq(0).keypress(function(event) {
console.log(event);
})
// Each Keyboard Key has a Keycode, for example Enter is 13
$('input').eq(0).keypress(function(event) {
if(event.which === 13){
$('h3').toggleClass("turnRed");
}
})
////////////
// ON() ///
//////////
// on() basically works like addEventListener()
$('h1').on("dblclick",function() {
$('h1').addClass('turnBlue');
})
$('li').on('mouseenter',function() {
$(this).toggleClass('turnRed');
})
/////////////////////////////
// EFFECTS and ANIMATIONS //
///////////////////////////
// http://api.jquery.com/category/effects/
$('input').eq(1).val("FADE OUT EVERYTHING");
$('input').eq(1).on("click",function(){
$(".container").fadeOut(3000) ;
})
$('input').eq(1).on("click",function(){
$(".container").slideUp(1000) ;
})