javascript - How to set the select to have the width of the selected option -


i have select element more options. select has width of longest option text size. how can set select have width of selected option? , when click select should have same width (of selected option), rest of options should have width of longest option text size.

anticipated thanks!

edit

i've posted wrong question. looking easyest method of doing this. css / js / jquery.

simply got selected text , wrap in span length , , resize select

try example :

     <select id="sel">          <option value="aaaa">aaaa</option>          <option value="aaaaaaaa">aaaaaaaa</option>          <option value="aaaaaaaaaaaa">aaaaaaaaaaaa</option>          <option value="aaaaaaaaaaaaaaaa">aaaaaaaaaaaaaaaa</option>          <option value="aaaaaaaaaaaaaaaaaaaa">aaaaaaaaaaaaaaaaaaaa</option>      </select>       <span id="hidnspan">       <span>  <script>  $(document).ready(function() {     $('#sel').change(function()     {         $('#sel').width( $('#hidnspan').html($('#sel').find(":selected").text()).width())     }); });   </script> 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -