Add addStyles

This commit is contained in:
Chalarangelo
2021-01-07 00:37:43 +02:00
parent 4e0b3b5f18
commit 6889e55250

20
snippets/addStyles.md Normal file
View File

@ -0,0 +1,20 @@
---
title: addStyles
tags: browser,beginner
---
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.
```js
const addStyles = (el, styles) => Object.assign(el.style, styles);
```
```js
addStyles(document.getElementById('my-element'), {
background: 'red',
color: '#ffff00',
fontSize: '3rem'
});
```