Tree Traversal Flashcards

1
Q

Get single element children

var children = element.children();

A

var children = element.children;

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

Get single element children filtered by selector

var children = element.children(‘div’);

A

var children = element.queryAll(‘> div’);

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

var children = elements.children();

A

ES6

var children = elements.map(x => […x.children]); children = [].concat(…children);

ES5

var children = elements.reduce(function(result, element) { return result.concat([].slice.call(element.children)); }, []);

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

Get children filtered by selector from a set of elements

var children = elements.children(‘div’);

A

ES6

var children = elements.map(x => x.queryAll(‘> div’)); children = [].concat(…children);

ES5

var children = elements.reduce(function(result, element) { return result.concat(element.queryAll(‘> div’)); }, []);

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

Get single elements contents

var contents = element.contents();

A

var contents = element.childNodes;

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

Get multiple elements contents

var contents = elements.contents();

A

ES6

var contents = elements.map(x => […x.childNodes]); contents = [].concat(…contents);

ES5

var contents = elements.reduce(function(result, element) { return result.concat([].slice.call(element.childNodes)); }, []);

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

Get closing matching parent for a single element

var closest = element.closest(‘div’);

A

var closest = element.closest(‘div’);

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

Get closest matching parent for a set of elements

var closest = elements.closest(‘div’);

A

ES6

var closest = elements.map(x => x.closest(‘div’));

ES5

var closest = elements.map(function(element) { return element.closest(‘div’); });

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

Find descendants of a single element

var found = element.find(‘div’);

A

var found = element.queryAll(‘div’);

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

Find descendants in the set of elements

var found = elements.find(‘div’);

A

ES6

var found = elements.map(x => x.queryAll(‘div’)); found = [].concat(…found);

ES5

var found = elements.reduce(function(result, element) { return result.concat(element.queryAll(‘div’)); }, []);

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

Get the next sibling for a single element

var next = element.next();

A

var next = element.nextElementSibling;

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

Get the next sibling filtered by selector for a single element

var next = element.next(‘div’);

A

var next = element.query(‘+ div’)

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

Get the next sibling for each element in the set

var next = elements.next();

A

ES6

var next = elements .map(x => x.nextElementSibling) .filter(x => x);

ES5

var next = []; elements.forEach(function(element) { if (element.nextElementSibling) next.push(element.nextElementSibling); });

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

Get the next sibling filtered by selector for each element in the set

var next = elements.next(‘div’);

A

ES6

var next = elements .map(x => x.query(‘+ div’)) .filter(x => x);

ES5

var next = []; elements.forEach(function(element) { if (element.nextElementSibling && element.nextElementSibling.matches(‘div’)) next.push(element.nextElementSibling); });

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

Get all the following sibling for an element

var next = element.nextAll();

A

var next = element.queryAll(‘~ *’);

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