General Attributes Flashcards

1
Q

Set attribute for a single element

element.attr(‘foo’, ‘bar’);

A

ment.setAttribute(‘foo’, ‘bar’);

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

Set attribute for a set of elements

elements.attr(‘foo’, ‘bar’);

A

ES6

elements.forEach(x => x.setAttribute(‘foo’, ‘bar’));

ES5

elements.forEach(function(element) { element.setAttribute(‘foo’, ‘bar’);

});

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

var value = element.getAttribute(‘foo’); Get plain object containing all element attributes as a name: value pairs

var value = element.attr(‘foo’);

A

var value = element.getAttribute(‘foo’);

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

Get a plain object containing all element attributes as key:value pairs

var attributes = element.attr();

A

ES6

var attributes = {};

for (var {name, value} of […element.attributes]) attributes[name] = value;

ES5

var attributes = {}; [].forEach.call(element.attributes, function(attr) {

attributes[attr.name] = attr.value;

});

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

Get the current value of the first element in the set of matched elements or set the value of every matched element. Get element value

var value = element.val();

A

var value = element.value;

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

element.val(‘foo’);

A

element.value = ‘foo’;

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

Set value of a set of elements

elements.val(‘foo’);

A

ES6

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

ES5

elements. forEach(function(element) {
element. value = ‘foo’;

});

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