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:
html<div id="elem">
text
</div>
Let's get a reference to it into a variable:
javascriptlet elem = document.querySelector('#elem');
We change the styles for it:
javascriptelem.style.color = 'red';
We read its styles:
javascriptconsole.log(elem.style.color); // shows 'red';