Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created November 9, 2011 21:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathantneal/1353017 to your computer and use it in GitHub Desktop.
Save jonathantneal/1353017 to your computer and use it in GitHub Desktop.
ie-currentStyle-without-reflow.js
(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