1. computed-style
Cross-browser currentStyle/getComputedStyle implementation
computed-style
Package: computed-style
Created by: twolfson
Last modified: Mon, 13 Jun 2022 20:33:30 GMT
Version: 0.3.0
Downloads: 855,917
Repository: https://github.com/twolfson/computedStyle

Install

npm install computed-style
yarn add computed-style

computedStyle

Cross-browser currentStyle/getComputedStyle implementation

testling-ci badge

Getting Started

Download one of the available flavors:

In your web page:

 <script src="dist/computedStyle.min.js"></script>
<script>
computedStyle(el, 'color'); // Returns color of the element
</script>

Documentation

computedStyle is a single purpose function

 computedStyle(element, property);
/**
 * Cross-browser getComputedStyle
 * @param {HTMLElement} el Element to get property from
 * @param {String} prop Property to look up (DOM, zIndex, and CSS, z-index, formats accepted)
 * @returns Property from the browser
 *
 * @note These properties can vary from browser to browser.
 * For example, IE6 will return #FF0000 whereas Firefox will return rgb(255, 0, 0)
 * I have chosen to avoid this for this repo as it exits the single purpose
 * and jQuery follows the same approach.
 */

Examples

 // Grab the z-index of an element
computedStyle(el, 'z-index');

// Grab the background-color of an element
computedStyle(el, 'background-color');

Donating

Support this project and others by twolfson via gratipay.

Support via Gratipay

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint your code using npm run lint and test via npm test.

License

Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code