title: How to add option to select optgroup in jquery?
body: <p>I'm trying to fill an html select with javascript. Now I simply do:</p>
  
  <pre><code>function addRow(selectID, testName) {
      var x = document.getElementById(selectID);
      var option = document.createElement("option");
      option.text = testName;
      x.add(option);
  }    
  
  for (var x = 0; x &lt; testSet.length; x++) {
      addRow('select', testSet[x]);
  }
  </code></pre>
  
  <p>where testSet is an array of string. In this way I have the filled select. Now I want to upgrade the fill of select using optgroup so, in my html code, I have</p>
  
  <pre><code>&lt;select onchange="selectionChanged()" 
  style="width: 400px; height: 20px; vertical-align: middle;"
  id="select"&gt;&lt;optgroup label="OptionSet1"&gt;&lt;/optgroup&gt;
  &lt;optgroup label="OptionSet2"&gt;&lt;/optgroup&gt;
  &lt;optgroup label="OptionSet3"&gt;&lt;/optgroup&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Now to fill with my options I think I must do something like that</p>
  
  <pre><code>for (var x = 0; x &lt; testSet.length; x++) {
      if(testSet[x].indexOf("string1") != -1){
         // Add testSet[x] in OptionSet1
      }
      if(testSet[x].indexOf("string2") != -1){
         // Add testSet[x] in OptionSet2
      }
      if(testSet[x].indexOf("string3") != -1){
          // Add testSet[x] in OptionSet3
      }
  }
  </code></pre>
  
  <p>What I must do to "Add testSet[x] in OptionSet"?
  I readed something on the web, but I cannot find anything that seems to work for me.</p>
  
  <p>Thank you.</p>