Files
30-seconds-of-code/snippets/addStyles.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

510 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
addStyles browser,beginner 2021-01-07T00:37:43+02:00 2021-01-07T00:37:43+02:00

Adds the provided styles to the given element.

  • Use Object.assign() and ElementCSSInlineStyle.style to merge the provided styles object into the style of the given element.
const addStyles = (el, styles) => Object.assign(el.style, styles);
addStyles(document.getElementById('my-element'), {
  background: 'red',
  color: '#ffff00',
  fontSize: '3rem'
});