jQuery Flashcards

1
Q

5 things that jquery makes it easy to do

A

Find - Elements in an HTML document

Change - HTML content

Listen - to what a user does and react accordingly

Animate content on a page

Talk - over the network to fetch new content

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

find an h1 in the DOM using jQuery and return the text that it contains

A
jQuery("h1");  
(important to not that it is a string wrapped in "")
or
$("h1").text();
$("#idName").text();
$(".className").text();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

find an h1 and change/add the text

A

$(“h1”).text(“new text here”);

note: need to make sure the DOM has finished loading the HTML content before we can reliably use jQuery

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

how to make sure that jquery is only run when the DOM is finished loading?

A

use the “ready” method. example:
jQuery(document).ready(functyion(){
$(“h1”).text(“new text here”);
});

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

how to get all of the li in an HTML list

A

$(“li”);

It returns an object with all of the line items

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

how to get the li of a of the “destinations” class

A

$(“.destinations li”);

if there are li’s that are children of the destination’s li’s then we will need to use the decedent selector if you want only the lis that are the direct children of destinations class. like this:
$(“.destinations > li”);

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

selecting multiple elements or specific elements in the array

A

multiple elements
$(.className, #idName);

specific list items
$(li: first): would select the first li
can also use: last, odd, even

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

how to find elements by traversing the DOM

A
$("#destinations").find("li");
or
$("li").first();
or
$("li").last();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to walk the DOM (get to the next or previous li for example)?

A

$(“li”).first().next();

$(“li”).last().prev();

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

how to “walk up” or “walk down” the DOM

A

$(“li”).parent();

$(“li”).children();

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

how to add (4 methods) elements of the DOM

A

Adding

var. appendTo(“element”);
var. prependTo(“element”);
var. insertAfter(“element”);
var. insertBefore(“element”);

Or 
$('item already in DOM').append('element')
$('item').prepend('element')
$('item').after('element')
$('item').before('element')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to remove an item from the DOM

A

$(‘item’).remove()

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

How to add an event listener to execute a function when a button is clicked.

Additionally, how would you only change the button that was clocked (as opposed to all of the buttons?

A
$('button').on('click', function(){
     //function here 
})

To apply it to only the button that was clicked…

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

How to add an event listener to execute a function when a button is clicked.

Additionally, how would you only change the button that was clocked (as opposed to all of the buttons?

A
$('button').on('click', function(){
     //function here 
})

To apply it to only the button that was clicked…

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

How to add an event listener to execute a function when a button is clicked.

Additionally, how would you only change the button that was clocked (as opposed to all of the buttons?

A
$('button').on('click', function(){
     //function here 
})

To apply it to only the button that was clicked…

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

How to append the var price to a button that was clicked to the nearest item of class .vacation

A

$(this).closest(‘.vacation’).append(price)

17
Q

how to find the data attribute in html through jquery

A

$(‘item’).data(‘dataName’);

18
Q

how to use event delegation (what is used in event handlers to target only specific elements of an item that has an event handler). in this case try to target only the ‘button’ element inside of the vacation class

A

$(‘.vacation).on(‘click’, ‘button’, function(){});

19
Q

how to get only the items that only fit criteria. in this example find only the elements that have the “.on-sale” class in the element that has a class of “.vacation”

A

$(‘.vacation’).filter(‘.on-sale.’);

20
Q

how to add or remove classes from an element (use $(‘.vacation’).filter(‘.on-sale.’); as the elements that you want to add or remove the class ‘.highlighted’)

A

$(‘.vacation’).filter(‘.on-sale.’).addClass(‘highlighted’);

$(‘.highlighted’).addClass(‘highlighted’);