17 lines
359 B
Markdown
17 lines
359 B
Markdown
---
|
|
title: getStyle
|
|
tags: browser,css,beginner
|
|
---
|
|
|
|
Retrieves the value of a CSS rule for the specified element.
|
|
|
|
- Use `Window.getComputedStyle()` to get the value of the CSS rule for the specified element.
|
|
|
|
```js
|
|
const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
|
|
```
|
|
|
|
```js
|
|
getStyle(document.querySelector('p'), 'font-size'); // '16px'
|
|
```
|