How get the width of an input element in IE?
I dont work with a framework, i'm working with JavaScript by default.
I need to know the width of an input text element, in the good browsers i use:
width = document.defaultView.getComputedStyle(el, "").getPropertyValue('width');
But in the f**ing Internet Explorer use:
if (typeof el.currentStyle['width'] == "undefined" || el.currentStyle['width'] == 'NaN') {
width = el.currentStyle['width'];
} else {
width = null;
}
This works, if it is set the w开发者_开发问答idth by css or style propertie, but if the size is a default (set by size propertie or dont set) el.currentStyle['width'] is undefined.
I need to know the width of an element without propertie set.
var elwidth= el.offsetWidth+'px';
Just use Jquery. It has .width and .height functions which work in ie6 as well.
精彩评论