title: jQuery Loop through selects and set selected option
body: <p>I'd like to loop through all of the select inputs on a page and if the selected value is not a certain option then set that value to selected</p>
  
  <p>I have some selects</p>
  
  <pre><code>&lt;select name="select1"&gt;
    &lt;option value="1"&gt;One&lt;/option&gt;
    &lt;option value="2" selected&gt;Two&lt;/option&gt;
    &lt;option value="3"&gt;Three&lt;/option&gt;
    &lt;option value="4"&gt;Four&lt;/option&gt;
    &lt;option value="5"&gt;Five&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select name="select2"&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;option value="4"&gt;Four&lt;/option&gt;
    &lt;option value="5"&gt;Five&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select name="select3"&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;option value="4"&gt;Four&lt;/option&gt;
    &lt;option value="5"&gt;Five&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I'm looping through them like so, but I can't figure out how to set the selected property to option '2' if it isn't already selected</p>
  
  <pre><code>$('select').each(function() {
  
      var selected = $(this).find(":selected");
  
      if (selected.val() != 2) {
          // do some stuff
  
      }
  
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I should elaborate. If a select input value is changed, I'm appending a string e.g. '-updated' to the input value as each input will be posting off to a database. Ideally I'd only do this for inputs that have changed for efficiency</p>
  
  <p>So I'd like to set all selects inputs that don't already have option 2 selected to be selected and have a value of "2-updated"</p>
  
  <p>Thanks for all of the answers so far</p>