JQuery Flashcards

1
Q

What is a Java library?

A

A reusable bundle of JavaScript functionality. Its JavaScript code stored on a server. It can be accessed and reused by others.

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

What is a CDN?

A

A content delivery network is a server optimized for serving static files like JS libraries and doing it very quickly.

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

How does a library fit into the design of a webpage?

A

A webpage is made up of the user interface (HTML+CSS), interactivity (JS+DOM), and data (which we often bring in through JS). A JS library may take the place of any or all of these parts.

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

What is jQuery?

A

It is the most popular JavaScript library. It give developers lots of useful functions so they can make their webpage interactive across multiple browsers. It is an open source library with a big community of contributors.

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

What is the main function in jQuery?

A

$. $(“h1”) finds all the h1’s on a page and stores them in a collection (array).

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

How does JQuery change text of a tag?

A

$(“p”).text(“message”);

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

What is the syntax of selectors in the JQuery function?

A

$(“p”);
$(“#identifierName”);
$(“.className”);

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

How is jQuery used to get text from an element?

A
var variableName = $("#identifierName").text();
The method call with no variables passed to the method returns what is inside the tag with the identity of identifierName.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the general way to associate an element with a variable using jQuery?

A

var $variableName = $(“#identifierName”);
It is customary to use a $ to start a variable that stores jQuery object.
Then you can $variableName.text() to get text. You would also say $variableName.text($variableName.text() + “new text to append to the old stuff”);

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

What is the method for passing HTML rather than just text?

A

.html rather than .text

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

How is a class name added to an element?

A

$(“a”).addClass(“className”);

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

How is a CSS rule added to an element?

A

$(“a”).css(“color”, “green”);

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

How is an attribute changed or added to an element?

A

$(“a”).attr(“href”, “URL”);

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

How is an element created and added to a webpage?

A

var $newP=$(“<p>”);

$(“body”).append($newP);</p>

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

What is the difference between a DOM element and a jQuery collection?

A
1.  The DOM node is stored using var nameEL=document.getElementById("identifierName");
The jQuery collection is stored using var $nameEL=$("#identifierName");
2. Each item in the jQuery collection is a DOM node.
  1. The jQuery collection includes more methods to manipulate the data than a DOM node.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can a jQuery collection be converted to a DOM node?

A
Yes.
var nameEl=$nameEl[0];
var $nameEl=$(nameEl);
17
Q

Describe 2 ways of iterating through a jQuery collection?

A
  1. For Loop.
    a. Store the collection in a variable.
    b. Create a loop.
    c. Create a variable and put one element of the collection into it.
    d. Convert the variable to a collection.
    e. Then manipulate it.
  2. .each method
    a. Store the collection in a variable.
    b. Use the .each method on the variable
    c. Pass it a function
    d. In the function, creates a variable and put one element into the variable.
    e. Then manipulate it.
18
Q

What is the code for iterating through a jQuery collection using the .each method?

A

var $nameEls = $(“p”);
$nameEls.each(functionName(index, element){
var $nameEl=$(element or this);
$nameEl.html($nameEl.html()+”appended text”);
});

19
Q

What is chaining?

A

Adding a method after a method has already been called. For example.
$(“<img></img>”).attr(“src”, “URL”)
.attr(“width”, “100”)
.appendTo(“body”);

20
Q

How is an event listener added via jQuery?

A

Use the .on method.

$(“#identifierName”).on(“click”, function(){});

21
Q

Where can you find the full list of browser events?

A

developer.mozilla.org

22
Q

What is the ready function?

A
It allows the developer to include script anywhere on the page.  It will run whatever is in the function after the page is loaded.
Example,
$(document).ready(function(){
	code to call after page loads;
});
23
Q

How would one use jQuery to evaluate a form submission?

A
  1. Use .on to add an event listener to the form for “submit”
  2. Use prevent default to stop the page reload
  3. Use .val() to get the value of the selection.
  4. Compare with something and take an action.
24
Q

Give an example of using jQuery to evaluate a form submission?

A

$(“#quiz-form”).on(“submit”, function(event) {
event.preventDefault();
var $answer = $(“#quiz-answer”);
var answer = $answer.val();
console.log(answer);
if (answer === “crocodile”) {
$(“#result”).text(“Woweeee! You got it! WOOO PARTY!”);
} else {
$(“#result”).text(“Try again!”);
}
)};

25
Q

How can you select something via an attribute?

A

$(“identifierName”).find(“[name=species”]);

26
Q

When using the .on function, what can help with the code in the passed function?

A
$(this) refers to the element identified and to which the event listener is attached.
    $("form").on("submit", function() {
      // store the value of the input with name='age' 
       var age = $(this).find('[name=age]').val();
    });
27
Q

What are some common jQuery animation methods?

A
.hide();
.show();
.slideDown();
.fadeIn()
.animate({
  width: "400px",
  marginLeft: "30px",
borderWidth: "10px"
}, 1500);
28
Q

Can you pass a function to .slideDown();?

A

Yes. The function will then be called after the .slideDown method is complete.
$(“#croc-pic”).slideDown(1000, function() {
$(“#croc-text”).
});

29
Q

What is special about .animate?

A

It allows for more control. A developer can set the final CSS values in the animate function and it will grow or shrink to that value over the time designated.