title: Appending options to a select, using jQuery, resizes it?
body: <p>In this small, but full example, I am trying to recreate a dual list box UI component.  I simply wish to be able to move items from one box to another.  (Would be nice if I could add sorting, but one hurdle at a time I think!)</p>
  
  <p>I am getting a problem with this code in IE7 (FF, Chrome, Opera all seem to work fine). Whenever I move items from one list to another, the select box resizes (shrinks) each iteration.  I'm not really sure where I am going wrong here, can anyone shed some insight?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
   &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
    &lt;title&gt;Dual List Testing&lt;/title&gt;
    &lt;link type="text/css" href="css/smoothness/jquery-ui-1.7.2.custom.css" rel="stylesheet" /&gt; 
    &lt;script type="text/javascript" src="js/jquery-1.3.2.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
     $(function(){
      //hover states on the static widgets
      $('.dual-box &gt; .button-panel &gt; .button').hover(
       function() { $(this).addClass('ui-state-hover'); }, 
       function() { $(this).removeClass('ui-state-hover'); }
      );    
     });
  
     // Hack the buttons of the dual-list to the centre (couldn't figure out a css solution)
     $(function(){
      $('#dualBox1 .button-panel').css("padding-top",($('.button-panel').height()-(34*4))/2); // v-centre
      $('#dualBox1 .button').css("margin-left", ($('.button-panel').width()-34)/2); // h-centre
     });
  
     $(function(){   
      $('#dualBox1 .add').click(function () {
         $('#dualBox1 .list-box:first select option:selected').appendTo('#dualBox1 .list-box:last select');
      });
      $('#dualBox1 .remove').click(function () {
        $('#dualBox1 .list-box:last select option:selected').appendTo('#dualBox1 .list-box:first select');
      });
      $('#dualBox1 .addall').click(function () {
        $('#dualBox1 .list-box:first select option').appendTo('#dualBox1 .list-box:last select');
      });
      $('#dualBox1 .removeall').click(function () {
        $('#dualBox1 .list-box:last select option').appendTo('#dualBox1 .list-box:first select');
      });
     });
    &lt;/script&gt;
    &lt;style type="text/css"&gt;
     .dual-box 
     {
      width: 500px;
      height: 200px;
     }
  
     .dual-box &gt; .list-box
     {
      width: 45%;
      height: 100%;
  
      background-color:#f00;
  
      float: left;
     }
  
     .dual-box &gt; .list-box &gt; select
     {
      height: 100%;
      width: 100%;   
     }
  
     .dual-box &gt; .button-panel
     {
      width: 10%;
      height: 100%;
  
      float: left;
     }   
     .dual-box &gt; .button-panel &gt; .button
     {
      width:auto;
  
      margin-bottom: 2px;
      margin-left: auto;
      margin-right: auto;
  
      padding: 8px 0;
      cursor: pointer;
      float: left;
     }
  
     .dual-box &gt; .button-panel &gt; .button &gt; span.ui-icon
     {
      float: left; 
      margin: 0 8px;
     }
  
    &lt;/style&gt; 
   &lt;/head&gt;
   &lt;body&gt;  
    &lt;div id="dualBox1" class="dual-box"&gt;
     &lt;div class="list-box"&gt;
      &lt;select multiple="multiple"&gt;
       &lt;option value="1"&gt;Test 1&lt;/option&gt;
       &lt;option value="2"&gt;Test 2&lt;/option&gt;
       &lt;option value="3"&gt;Test 3&lt;/option&gt;
       &lt;option value="4"&gt;Test 4&lt;/option&gt;
      &lt;/select&gt;
     &lt;/div&gt;
  
     &lt;div class="button-panel"&gt;
      &lt;div class="button add ui-state-default ui-corner-all"&gt;
       &lt;span class="ui-icon ui-icon-arrowthick-1-e"&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="button addall ui-state-default ui-corner-all"&gt;
       &lt;span class="ui-icon ui-icon-arrowthickstop-1-e"&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="button removeall ui-state-default ui-corner-all"&gt;
       &lt;span class="ui-icon ui-icon-arrowthickstop-1-w"&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="button remove ui-state-default ui-corner-all"&gt;
       &lt;span class="ui-icon ui-icon-arrowthick-1-w"&gt;&lt;/span&gt;
      &lt;/div&gt;
     &lt;/div&gt;
  
     &lt;div class="list-box"&gt;
      &lt;select multiple="multiple"&gt;
       &lt;option value="5"&gt;Test 5&lt;/option&gt;
      &lt;/select&gt;
     &lt;/div&gt;
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks, </p>
  
  <p><strong>Update:</strong> I've been trying to look at this from all angles.  I wondered if my JS was to blame, but looking at this through firefox seems to rule that out.  Have I ran into a browser bug here?</p>
  
  <p><strong>Update 2:</strong> Okay, I've tracked this to be IE not liking percentage sizes to be set on the select element (although it picks this value up fine origionally, it breaks after you manipulate the element somehow).  Executing the following 2 lines of jQuery seems to resolve the issue:</p>
  
  <pre><code>$('.dual-box &gt; .list-box &gt; select').height($('.dual-box').height());
  $('.dual-box &gt; .list-box &gt; select').width(($('.dual-box').width()/100)*45);
  </code></pre>
  
  <p>I was kinda hoping for this not to become a hack on top of a hack, but unfortunately it seems to of.  Does anyone have a clean way of resolving this issue?</p>