// create a helper function
function setAttributes(el, attrs) {
for(var key in attrs) {
el.setAttribute(key, attrs[key]);
}
}
// call like this
setAttributes(elem, {"src": "http://example.com/something.jpeg", "height": "100%", ...});
function setAttributes(element, attributes) {
Object.keys(attributes).forEach(attr => {
element.setAttribute(attr, attributes[attr]);
});
}
const attributes = {
name: 'example',
title: 'Box 1',
disabled: '',
style: 'background-color: salmon; color: white;',
};
const button = document.getElementById('btn');
setAttributes(button, attributes);
Object.assign(element,{...attributes})