With the following I can get the width of a select input in pixels. Is it possible to get the width of an option within the select list? Thanks
$('#mySelect').width();
UPDATE – heres the reason I want this. I need to center text in a select list. I cant do this cross device and browser with css text-align: center; My only option is to use text-indent. As my site has a liquid width and the options are of different lengths, I need to calculate this value dynamically.
So, if I could get the width of the select option text, and also get the width of the container (much easier), then I could calculate what the text-indent should be. Thanks
NimChimpsky’s method seems to work fine. Code is here: jQuery – function runs fine when fired on div click, but not on page load
you can get string length of selected option like so :
and for a specific index element (2 here) do this :
Alternatively you could take the selected text, put it in an invisible div, then get the width of that div – using normal jquery width method.