I am trying to get the width of several hidden select elements. Using width () in jQuery objects returns a width, which is the width defined by CSS, but includes padding. As soon as I switch the elements to show, though, calling width () returns the correct value (i.e. Width, which excludes padding / border / margins).
HTML sample:
<span id="test" style="visibility:hidden"> <select id="one"> <option>1</option><option>2</option><option>3</option> </select> </span>
CSS
select { width: 80px; padding: 0 0 0 15px; }
Expected Width: 65, Reported Width: 80
Here JSFiddle demonstrates my problem: http://jsfiddle.net/2RH7C/4/
Is there a workaround besides setting "visibility: hidden" (instead of showing: no) or cloning / moving objects off the screen? I use KnockoutJS data bindings to control the visibility and display of the binding: none (http://knockoutjs.com/documentation/visible-binding.html).
source share