Files
30-seconds-of-code/snippets/get-style.md
2023-04-28 22:29:23 +03:00

443 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Get style for element snippet
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'