Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 429 Bytes

change-element-style.md

File metadata and controls

18 lines (16 loc) · 429 Bytes
title description author tags
Change Element Style
Changes the inline style of an element.
axorax
dom,style
const changeElementStyle = (element, styleObj) => {
  Object.entries(styleObj).forEach(([property, value]) => {
    element.style[property] = value;
  });
};

// Usage:
const element = document.querySelector('.my-element');
changeElementStyle(element, { color: 'red', backgroundColor: 'yellow' });