Created
April 23, 2012 13:29
-
-
Save eikes/2470949 to your computer and use it in GitHub Desktop.
Determine html element width without jquery
This file contains hidden or 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 to determine the width of any element in pixel: | |
| getElementWidth = function (node) { | |
| var ow = node.offsetWidth, | |
| cs = node.currentStyle && node.currentStyle["width"] | |
| || getComputedStyle && getComputedStyle(node, null).getPropertyValue("width"), | |
| result = parseFloat(ow || cs); | |
| if (cs && cs.match(/%/)) | |
| return (parseFloat(cs) / 100) * getElementWidth(node.parentNode); | |
| if (isNaN(result) || result == 0) | |
| return getElementWidth(node.parentNode); | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment