Class Attributes Flashcards

1
Q

Add single class to element.

element.addClass(‘foo’);

A

element.classList.add(‘foo’);

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

Add multiple classes

element.addClass(‘a b c’);

A

element.classList.add(‘a’, ‘b’, ‘c’);

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

Add class(es) to a set of elements

elements.addClass(‘foo’);

A

ES6

elements.forEach(x => x.classList.add(‘foo’));

ES5

elements.forEach(function(element) { element.classList.add(‘foo’);

});

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

Remove a single class

element.removeClass(‘foo’);

A

element.classList.remove(‘foo’);

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

Remove multiple classes

element.removeClass(‘a b c’);

A

element.classList.remove(‘a’, ‘b’, ‘c’);

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

Remove classes from a set of elements.

elements.removeClass(‘foo’);

A

ES6

elements.forEach(x => x.classList.remove(‘foo’));

ES5

elements.forEach(function(element) { element.classList.remove(‘foo’);

});

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

element.toggleClass(‘foo’);

A

element.classList.toggle(‘foo’);

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

Conditionally toggle a class

element.toggleClass(‘foo’, codition);

condition result is either true or false

A

element.classList.toggle(‘foo’, codition);

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

Toggle class on a set of elements.

elements.toggleClass(‘foo’);

A

ES6

elements.forEach(x => x.classList.toggle(‘foo’));

ES5

elements.forEach(function(element) { element.classList.toggle(‘foo’);

});

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

Check if a single element has a class.

var has = element.hasClass(‘foo’);

A

var has = element.classList.contains(‘foo’);

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

Check if at least one of the elements in a set of elements has a certain class

var has = elements.hasClass(‘foo’);

A

ES6

var has = elements.some(x => x.classList.contains(‘foo’));

ES5

var has = elements.some(function(element) { return element.classList.contains(‘foo’);

});

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