Created
May 2, 2012 12:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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