title: Jquery Change Selected Option by Value
body: <p>how can i change selected option by value? Select object when loaded One selected by default I wanna set it by value.</p>
  
  <pre><code>&lt;select id="county"&gt;
    &lt;option value="1"&gt;One&lt;/option&gt;
    &lt;option value="2"&gt;Two&lt;/option&gt;
    &lt;option value="3"&gt;Three&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>var $county_id = $('#county_id');
      var $city_id = $('#city_id').val();
  
      var $selected_county = $('#selectedCounty').val();
  
  
  
      $county_id.html('');
  
      $.get('/base/get_city_counties',{city_id:$city_id},function(res){
          res = eval('('+res+')');
          var len = res.length,i,$option = $('&lt;option&gt;'),$option_;
          for(i=0;i&lt;len;i++)
          {
              $option_ = $option.clone(true).val(res[i][0]).html(res[i][1]);
              $county_id.append($option_);
          }
      });
  
      $('#county option[value=2]').attr('selected','selected');
  </code></pre>
  
  <p>fixed the code its working thx for helping. Placement was wrong I fixed.</p>
  
  <pre><code>$( document ).ready( function() {
      var $county_id = $('#county_id');
      var $city_id = $('#city_id').val();
      var $selected_county = $('#selectedCounty').val();
      $county_id.html('');
      $.get('/base/get_city_counties',{city_id:$city_id},function(res){
          res = eval('('+res+')');
          var len = res.length,i,$option = $('&lt;option&gt;'),$option_;
          for(i=0;i&lt;len;i++)
          {
              $option_ = $option.clone(true).val(res[i][0]).html(res[i][1]);
              $county_id.append($option_);
          }
          $('#county_id').val($selected_county);
      });
      $( 'textarea#jobdesc' ).ckeditor();
  } );
  </code></pre>