aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/elements.js
diff options
context:
space:
mode:
authorAlbin Larsson <mail@albinlarsson.com>2018-06-15 22:52:19 +0200
committerAlbin Larsson <mail@albinlarsson.com>2018-06-15 22:52:19 +0200
commitf1c4752036f58e01df95c30cc9cba4156a0737cd (patch)
tree2564570a6d5eaf1d582c8c5b95c7ab9efca9e55c /src/js/utils/elements.js
parentd522e405942e060180c7f5b28c914028e94a917b (diff)
downloadplyr-f1c4752036f58e01df95c30cc9cba4156a0737cd.tar.lz
plyr-f1c4752036f58e01df95c30cc9cba4156a0737cd.tar.xz
plyr-f1c4752036f58e01df95c30cc9cba4156a0737cd.zip
Filter out null / undefined in elements.setAttributes
Diffstat (limited to 'src/js/utils/elements.js')
-rw-r--r--src/js/utils/elements.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js
index 39b944d2..2d314ed8 100644
--- a/src/js/utils/elements.js
+++ b/src/js/utils/elements.js
@@ -42,9 +42,11 @@ export function setAttributes(element, attributes) {
return;
}
- Object.entries(attributes).forEach(([key, value]) => {
- element.setAttribute(key, value);
- });
+ // Assume null and undefined attributes should be left out,
+ // Setting them would otherwise convert them to "null" and "undefined"
+ Object.entries(attributes)
+ .filter(([, value]) => !is.nullOrUndefined(value))
+ .forEach(([key, value]) => element.setAttribute(key, value));
}
// Create a DocumentFragment