Files
30-seconds-of-code/snippets/getStyle.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

463 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Get style for element browser,css frog-blue-flower 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'