Files
30-seconds-of-code/snippets/add-styles.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

558 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Add styles to HTML element browser chalarangelo digital-nomad-14 2021-01-07T00:37:43+02:00 2021-01-07T00:37:43+02:00

Adds the provided styles to the given HTML element.

  • Use Object.assign() and HTMLElement.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'
});