Files
30-seconds-of-code/snippets/getStyle.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

435 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
getStyle browser,css,beginner 2017-12-29T00:08:17+02:00 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'