Element here refers to the element you’ve selected with querySelector.
pseudoElement here refers to the string of the pseudo element you’re trying to get (if any). You can omit this value if you’re not selecting a pseudo element.
Let’s walk through an example to help make sense of things. Say you have the following HTML and CSS:
<div class="element"> This is my element </div>
.element { background-color: red }
First, you need to select the element with querySelector. Then, you use getComputedStyle to get the element’s styles.
const element = document.querySelector('.element')
const style = getComputedStyle(element)
If you log style, you should see an object that contains every CSS property and their respective values.
You can also see this object in Chrome’s and Firefox’s dev tools.
For Firefox dev tools, look under “Inspector”, “Computed”.
For Chrome dev tools, look under “Elements”. If the dev tools window is large, you can see the computed styles on the right panel. If the dev tools window is small, you can look under the “Computed” tab.
To get the value of a CSS property, you write the property in camel case.
const element = document.querySelector('.element')
pseudoElementStyle = getComputedStyle(element, '::before')
console.log(pseudoElementStyle.content) // Before pseudo element
Exercise
Say you have the following HTML. Get its styles with both the style property and getComputedStyle. What’s the difference between the values of these properties?
<div style="color: red; background-color: white; font-size: 5em">Big red text!</div>