Skip to content

Instantly share code, notes, and snippets.

@robbieferrero
Created December 17, 2017 04:34
Show Gist options
  • Save robbieferrero/0f1ae910ee7a5db601a531a55a710baa to your computer and use it in GitHub Desktop.
Save robbieferrero/0f1ae910ee7a5db601a531a55a710baa to your computer and use it in GitHub Desktop.
getStyleValue
/**
*
* @param el Element
* @param CSS property in hyphen case
* @param pseudo pseudo selector (optional)
*/
function getStyleValue(el, property, pseudo) {
// convert hyphen-case to camelCase
const elStyle = el.style[property.replace(/(\-[a-z])/g, $1 => $1.toUpperCase().replace('-',''))];
return ((elStyle !== '' && !pseudo)
? elStyle
: window.getComputedStyle(el, pseudo).getPropertyValue(property));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment