0

I've got this code:

let myId = document.getElementById('myID');
myId.style.backgroundColor = 'black';
myId.style.color = 'green';

Is there a way to group all css code in one group omitting the "myId.style" prefix? Like in {}?

Dr. Avri
  • 11
  • 4

1 Answers1

0

You can do it like this:

myId.style.cssText = "display: block; position: absolute";

or maybe with es6 like this:

myId.style.cssText = ```
  display: block;
  position: absolute;
```

This question was already mentioned here: https://stackoverflow.com/a/3968772/3865116

vedran
  • 1,106
  • 2
  • 13
  • 18