jQuery Flashcards

1
Q

What is jQuery?

A
The most popular JS library
Takes the traditional DOM manipulation methods, and makes it easier and efficient in fewer lines of code
Example:
Traditional
document.querySelector(“h1”)
JQuery
$(“h1”)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to incorporate jQuery into Websites

A

Easiest way is to use a CDN method
CDN is basically a network of connected servers. CDN then finds the easiest and fastest method to retrieve files.
Place the jQuery CDN script above the javascript at directly above the ending body tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Selecting Elements with jQuery

A
jQuery(“ < CSS Selector > ”)
OR
$(“ < CSS Selector > ”)
$() == jQuery()
There is no difference between selecting all elements vs one element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Manipulating Styles with…

A

jQuery

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

To set the style

A

.css(< Attribute to change>, )
Example
$(“h1”).css(“color”, “red”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To get the style

A

.css(< Attribute to get >);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Separate concerns

A

jQuery is implemented in the .js file, and we can also use it to style the page
But styling the page in a .js file is bad practice
So the correct thing to do is create a css class inside the styles.css, and use jQuery to set the style to that class in the styles.css via .addClass()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Add/Remove class

A
.addClass(< CSS class to change style to, can be multiple classes which are separated by a single space>);
.removeClass(< CSS class to change style to, can be multiple classes which are separated by a single space >);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Check if an element has a class

A

.hasClass( < class to check if exists > )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Manipulating Text with jQuery

A

2 Methods

  1. .text( < New Text> );
  2. .html(< New HTML >);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Manipulating Attributes with…

A

jQuery

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Set Attribute

A

.attr(< Attribute to change>, < New Attribute Value>)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Get Attribute

A

.attr(< Attribute to check>)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Adding Event Listeners with…

A

…jQuery

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Click Listener

A

.click( < Callback function> );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Key Press Listener

A

.keypress( < Callback function> );

17
Q

General/Flexible Method

A

.on( < Event > ,< Callback function> );

18
Q

Adding and Removing Elements with…

A

jQuery

19
Q

Adding an Element

A

Adding a new element before a selected element

.before(< HTML of New Element >);

20
Q

Adding a new element after a selected element

A

.after(< HTML of New Element >);

21
Q

Prepend a new element inside of a selected element

A

.prepend(< HTML of New Element >);

22
Q

Append a new element inside of a selected element

A

.append(< HTML of New Element >);

23
Q

Web Animations with….

A

jQuery

24
Q

Hiding an element

A

.hide();

Element gets removed from the flow of the HTML structure of the web page

25
Q

Show an element

A

.show();

26
Q

Toggle hide and show

A

.toggle();

27
Q

FadeOut

A

Hides the element but in a less sudden way

.fadeOut();

28
Q

FadeIn

A

Shows the element but in a less sudden way

.fadeIn();

29
Q

Toggle fade in and fade out

A

.fadeToggle();

30
Q

Slide Up

A

Collapses an element

.slideUp();

31
Q

Slide Down

A

Uncollapse an element

.slideDown();

32
Q

Toggle Slide In and Slide Out

A

.slideToggle();

33
Q

Method for more Control Over Animations

A

.animate( { < New CSS Rule to Animate>});

Can only add CSS rules that have a numeric value

34
Q

Can also chain animation methods back to back

A

Example:

$(“h1”).slideUp().slideDown().animate({opacity: 0.5});