Files
30-seconds-of-code/snippets/js/s/get-style.md
2023-05-07 16:07:29 +03:00

464 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Get style for element snippet javascript
browser
css
frog-blue-flower 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.
const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
getStyle(document.querySelector('p'), 'font-size'); // '16px'