-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (54 loc) · 1.78 KB
/
Copy pathindex.js
File metadata and controls
67 lines (54 loc) · 1.78 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
$(document).ready(function() { //jQuery to check if the library is loaded before executing jQuery methods
$("body").css("background-color","white");
});
//jQuery selector vs. DOM selector
$("button");
document.querySelector("button");
document.querySelectorAll("button");
//jQuery manipulate styles
$("h1").css("color", "green");
$("h1").css("font-size", "5rem");
//Manipulate styles by adding CSS classes (aligns with UI design principles)
$("h1").addClass("big-title");
$("h1").removeClass("big-title");
$("h1").addClass("big-title");
//Add multiple classes
$("h1").addClass("big-title margin-50");
$("h1").hasClass("margin-50");
//Manipulating Text
$("h1").text("Bye");
$("#button2").text("Don't Click"); //selecting by id
//Manipulating Attributes
$("a").attr("href"); //Get
$("a").attr("href", "https://www.yahoo.com");
//jQuery Event Listener
$("h1").click(function() {
$("h1").css("color", "purple");
});
$("input").keydown(function(event) {
console.log(event.key);
})
$(document).keydown(function(event) { //listens to the whole document
$("h1").text(event.key);
})
//Use on for any other event types (see docs for which one you need)
$("h1").on("mouseover", function(){
$("h1").css("color", "purple");
});
//Adding and Removing elements w/ jQuery
$("h1").before("<button>New Button<\button>");
$("h1").after("<button>New Button<\button>");
$("h1").prepend("<button>New Button<\button>");
$("h1").append("<button>New Button<\button>");
//Removes Button:
//$("button").remove();
//Webiste Animations
$("button").on("click", function(){
//$("h1").hide(); hides
//$("h1").show(); shows
$("h1").toggle(); //alternates between hiding and showing
});
//multiple animations
$("#button2").on("click", function() {
$("h1").slideUp().slideDown().animate({opacity: 0.5});
});