jQuery Fundamentals Flashcards

1
Q

How does the for each function work with a set of jquery elements?

A

$someEls.each( function( index, element ) { // act on els } );

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

What is the difference between $(element) and $(this) in a jquery().each() loop?

A

they’re the same

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

What’s the difference between el.append() and el.after()

A

append treats ‘el’ as parent, and puts something inside it at the end. After simply puts something after the element.

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

What jQuery method sets and overrides default options in a plugin?

A

$.extend( { key1: defaultVal1, key2: defaultVal2 }, overrides ); // the overrides var would be passed into the plugin

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

Will this work? $.extend( { someObj { }, someKey: val }, overrides } );

A

No, because extend doesn’t do a deep merge. Add “true” to make it work.

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

How does $.each() work?

A

It takes an array or an object as the first argument and a callback as the second. Callback: function( key, objValProp) {} or else function ( index, objValue ) depending on object or array.

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

Search for class “box” inside of the #main section using context parameter.

A

$( “.box”, “#main”);

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

Get a set of all paragraph elements inside div id=”main” as well as the div. That is, return a set of p’s and div#main.

A

$(“#main”).find(“p”).andSelf(); // or $(“p”, “#main”).andSelf()

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

Get or set an attribute like id or src

A

$(“#someElement”).attr( “id”, “newID” ); // set

$(“#el”).attr( “id” ); // get

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

Set multiple attributes at once on an element

A

$( “el” ).attr( { “id”: “newID”, “title”: “newTitle” } );

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

What’s the difference between $( ‘p’ ).html() and $( ‘p’ ).text() ?

A

html() returns all the unescaped characters and attributes (e.g for bold text or spans). Text() only returns the text.

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

What’s the difference between $( ‘p’ ).html() and $( ‘p’ ).text() ?

A

html() returns all the unescaped characters and attributes (e.g for bold text or spans). Text() only returns the text.

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

Fastest way to select all direct children of a node?

A

$( someNode ).children(); // faster than $(“ node > * “);

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

What’s main difference between $(“div”).find(“.someClass”) and .filter( “.someClass” );

A

Find looks to all the children of div collection and filter looks to only the div collection

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

What’s main difference between $(“div”).find(“.someClass”) and .filter( “.someClass” );

A

Find looks to all the children of div collection and filter looks to only the div collection

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

What’s the difference between jquery array map() and js array map() ?

A

$.map( myArray, function( el, i ) { return el + i; });

myArray.map( function (el, i){ return el + i; });

17
Q

What’s the difference between jquery array map() and js array map() ?

A

$.map( myArray, function( el, i ) { return el + i; });

myArray.map( function (el, i){ return el + i; });

18
Q

what is the vanilla js version of html() function?

A

.innerHTML which isn’t a function and is faster.