Styling via style attribute in JavaScript

Let's remember how to style elements using the style attribute. Let's say we have the following element:

<div id="elem"> text </div>

Let's get a reference to it into a variable:

let elem = document.querySelector('#elem');

We change the styles for it: = 'red';

We read its styles:

console.log(; // shows 'red';