Get style for element

JavaScript, Browser, CSS · Oct 19, 2020

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'

More like this

  • Set style for element

    Sets the value of a CSS rule for the specified HTML element.

    JavaScript, Browser · Oct 22, 2020

  • Hide elements

    Hides all the elements specified.

    JavaScript, Browser · Sep 15, 2020

  • Show elements

    Shows all the elements specified.

    JavaScript, Browser · Oct 22, 2020