Skip to content

Instantly share code, notes, and snippets.

@jwalsh
Created May 2, 2012 12:30
Show Gist options
  • Save jwalsh/2576242 to your computer and use it in GitHub Desktop.
Save jwalsh/2576242 to your computer and use it in GitHub Desktop.
Third-Party JavaScript version 8: Listing 3.6: Finding the value of an element's style property
function getStyle(node, property, camel) {
var value;
if (window.getComputedStyle) {
value = document.defaultView
.getComputedStyle(node, null)
.getPropertyValue(property);
} else if (node.currentStyle) {
value = node.currentStyle[property] ?
node.currentStyle[property] :
node.currentStyle[camel];
}
if (value === 'transparent' ||
value === '' ||
value == 'rgba(0, 0, 0, 0)')
{
return getStyle(node.parentNode, property, camel);
} else {
return value || '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment