title: How to set select value dropdownlist in javascript via getElementByClassName or querySelector without id
body: <p>I am trying set select value dropdownlist in javascript. I have dropdownlist like following:</p>
  
  <pre><code>&lt;div class="gender_option" id="create"&gt;
      &lt;span class="value"&gt;
          &lt;select name="account" class="select-gender"&gt;
              &lt;option value="Unknown"&gt;Please select&lt;/option&gt;
              &lt;option value="Male"&gt;Male&lt;/option&gt;
              &lt;option value="Female"&gt;Female&lt;/option&gt;
          &lt;/select&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Firstly i tried by getElementByClassName. I searched lots of answer-question in stackoverflow and applied but it doesn't work again. 
  The below code is one of them. The code throws error like <code>undefined options</code>. I changed option instead of options but still doesn't work.</p>
  
  <pre><code>var e = document.getElementsByClassName('select_gender');
  e[1].options[e[1].selectedIndex].selected=true;
  </code></pre>
  
  <p>I examined and applied lots of solution like following explainations: 
  <a href="https://stackoverflow.com/questions/21281939/set-the-value-of-element-by-classname-without-having-the-elements-id">Set the value of element by classname, without having the element&#39;s ID</a>
  <a href="https://stackoverflow.com/questions/30445916/how-can-i-determine-the-value-of-the-selected-dropdown-option-using-getelementsb">How can I determine the value of the selected dropdown option using getElementsByClassName?</a></p>
  
  <p>Also i found queryselector i tried following code that doesn't work. </p>
  
  <pre><code>var selectElement = document.querySelector('.select_gender');
  var output1 = selectElement.options[selectElement.selectedIndex].value;
  
  for (var j=0; j&lt;output1.length; j++) {
      if (radioElements[i].getAttribute('value') == 'MALE') {
           output1[j].selected=true;
      }
  }
  </code></pre>
  
  <p>How can i set select value in javascript without id parameter  </p>
  
  <p>Ragards,</p>