It took 2 hours.
Other answers were incorrect for my case.
Comparing all the other answers in one post, adding my results with examples:
width() in jQuery
same as
clientWidth in JavaScript
for an element of type select
Sample code below, including output:
// NOTE: Give you element id below let eleId = 'myselectid1'; // 58 // includes padding into calculation // <head> // <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> // </head> // To enable below/jQuery, you would need above in HTML // alert( $('#' + eleId).width() ); // 58 // includes padding into calculation a = document.getElementById(eleId).clientWidth; alert(a); // 60 // includes border size and padding into width calculation a = document.getElementById(eleId).offsetWidth; alert(a); // 60 // includes border size and padding into width calculation a = document.getElementById(eleId).getBoundingClientRect().width; alert(a); // 60px (note the px in value, you may also get values like 'auto') // all dynamic values for all CSS properties, IE>=9 a = window.getComputedStyle(document.getElementById(eleId), null).getPropertyValue("width"); alert(a); // empty string // if you set it earlier, you would get this a = document.getElementById(eleId).style.height; alert(a); // undefined // only works on window object, not on element like select/ div - fails in older IE<9 a = document.getElementById(eleId).innerWidth; alert(a);
Hope this helps.
Manohar reddy poreddy
source share