diff options
Diffstat (limited to 'app/assets/javascripts/lib/utils/dom_utils.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/dom_utils.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/dom_utils.js b/app/assets/javascripts/lib/utils/dom_utils.js index f7687a929de..b52a736f153 100644 --- a/app/assets/javascripts/lib/utils/dom_utils.js +++ b/app/assets/javascripts/lib/utils/dom_utils.js @@ -89,3 +89,17 @@ export const getParents = (element) => { return parents; }; + +/** + * This method takes a HTML element and an object of attributes + * to save repeated calls to `setAttribute` when multiple + * attributes need to be set. + * + * @param {HTMLElement} el + * @param {Object} attributes + */ +export const setAttributes = (el, attributes) => { + Object.keys(attributes).forEach((key) => { + el.setAttribute(key, attributes[key]); + }); +}; |