title: Issue when I change the selected option in a dropdown the HTML don't refresh correctly
body: <p>I am working with a dropdown with countries. </p>
  
  <p>Originaly I have that the <strong>selected</strong> item is Ukraine.</p>
  
  <pre><code>&lt;select id="country" name="country"&gt;
      &lt;option value="US"&gt;USA&lt;/option&gt;
      &lt;option value="UG"&gt;Uganda&lt;/option&gt;
      &lt;option value="UA" selected&gt;Ukraine&lt;/option&gt;
      &lt;option value="AE"&gt;United Arab Emirates&lt;/option&gt;
      &lt;option value="GB"&gt;United Kingdom&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>With the next jQuery code I want to selected a different country:</p>
  
  <pre><code>$("select#country").val("GB");
  </code></pre>
  
  <p>In <strong>the dropdown now shows United Kingdom, but in the HTML still shows that Ukraine is the selected country</strong>, and I need that this change.</p>
  
  <p>I test differents solutions but seems no one works:</p>
  
  <ol>
  <li><p>I add .change() funtion, but the web start to make a infinity loop of refresing.</p>
  
  <pre><code>$("select#country").val(selectedOption).change();
  </code></pre></li>
  <li><p>I use different jQuery code, but all seems equals.</p>
  
  <pre><code>$("#country option[value="GB"]").attr('selected', 'selected');
  </code></pre></li>
  <li><p>I tried to use the .selectmenu('refresh') function but I need to update jQuery and I can't do that.</p>
  
  <pre><code>$("#country").selectmenu('refresh');
  </code></pre></li>
  </ol>
  
  <p>EDIT: The problem didn't was about jquery. It was problem how printed the HTML.</p>
  
  <pre><code>&lt;xsl:for-each select="$country"&gt; 
      &lt;xsl:attribute name="selected"&gt;
          &lt;xsl:text&gt;selected&lt;/xsl:text&gt;
      &lt;/xsl:attribute&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>
  
  <p>First, I print the list choosing the selected country. After there was a sorting of the list (I didn't see before). This sorting change the list but not the selected country. It was a timing problem, like I mark in the correct answer.</p>
  
  <p>Thx!</p>