Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

DOM element add multiple attributes

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);
Source by bobbyhadz.com #
 
PREVIOUS NEXT
Tagged: #DOM #element #add #multiple #attributes
ADD COMMENT
Topic
Name
6+7 =