title: How to loop and set the value of 2nd Span in Javascript?
body: <p>I have a query in which i want to set the value of second span in the div. </p>
  
  <pre><code>&lt;div id="content"&gt;
      &lt;h1&gt;Welcome&lt;/h1&gt;
      &lt;span&gt;This is the first span&lt;/span&gt;
      &lt;span&gt;This is the second span&lt;/span&gt;
      &lt;span&gt;This is the 3rd span&lt;/span&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I am using following javascript.</p>
  
  <pre><code>function SetValue(myValue) {
  
              var mainDiv = document.getElementById("content");
              for(var i=0;i&lt;mainDiv.childNodes.length;i++) {
                 if(mainDiv.childNodes[i] == 2) {
                     mainDiv.childNodes[i].innerText = myValue;
                 }
  
  
              }
          }
  </code></pre>
  
  <p>i want to get the parameter value to be set in second span of the main div</p>