I'm writing a jQuery plugin and something I need to be able to do is determine the width of an element that the user specifies. The problem is that .width() or .css('width') will always report exact pixels, even if the developer has assigned it e.g. width:90% with CSS.
Is there any way to have jQuery output the width of an element in px or % depending on what the developer has given it with CSS?
I'd say the best way is to compute it yourself:
var width = $('#someElt').width(); var parentWidth = $('#someElt').offsetParent().width(); var percent = 100*width/parentWidth;