Showing posts from July, 2011

Width of an element in javascript

When starting with the gwt-floating-header project i ran into some problems with getting, what i call, the" true width" of an element in javascript. With "true width" i mean the width of the element excluding padding, border and margin. And because i'm writing for GWT I don't have luxury of be able to use the .width() function in jQuery.
It took me a while to get the script to this point and i'm not really sure if it works for all browsers but it might help someone to get started.

function width(element) { var style = element.currentStyle || element.ownerDocument.defaultView.getComputedStyle(element, null); var safe = function(v) { return parseInt(v, 10) || 0; }; return element.offsetWidth - safe(style.paddingLeft) - safe(style.paddingRight) - safe(style.borderLeftWidth) - safe(style.borderRightWidth); }
GWT version of this snippet can be found here. Please let me know if you find any strangeness or incompatibilities in the code.


Floating table headers for GWT

Today I've created a Google code project for the GWT port of my jQuery floating header plugin. It's a very lightweight library that already supports both column and row headers. Since the code base is very young i haven't had the chance to try the compatibility with a lot of browsers but in time i might do this.

The project is available at: