Prepare repository for merge
This commit is contained in:
19
javascript/snippets/get-style.md
Normal file
19
javascript/snippets/get-style.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
title: Get style for element
|
||||
type: snippet
|
||||
tags: [browser,css]
|
||||
cover: frog-blue-flower
|
||||
dateModified: 2020-10-19T22:49:51+03:00
|
||||
---
|
||||
|
||||
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'
|
||||
```
|
||||
Reference in New Issue
Block a user