Created
November 9, 2011 21:02
-
-
Save jonathantneal/1353017 to your computer and use it in GitHub Desktop.
ie-currentStyle-without-reflow.js
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 (doc) { | |
var docEl = document.documentElement; | |
// get current style | |
window.getCurrentStyle = function (node) { | |
if (!node || !node.nodeName) return; | |
var docElClone = docEl.cloneNode(true), a, l, i; | |
for (a = docEl.getElementsByTagName(node.nodeName), l = a.length, i = 0; a[i] !== node; ++i); | |
return docElClone.getElementsByTagName(node.nodeName)[i].currentStyle; | |
}; | |
})(document); | |
// only works in IE6+ browsers (browsers with node.currentStyle) | |
// so is this one of those rare instances where IE wins? | |
// example: | |
// <style> span { font-size: 50px; } </style><div style="font-size:100px;"><span><b id="test"></b></span></div> | |
// <script> console.log( getCurrentStyle(document.getElementById('test')).fontSize === '50px'); </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment