title: Get the element name attribute in JavaScript
body: <p>How can I get the element <code>name</code> attribute in JavaScript?</p>
  
  <p><em>HTML :</em></p>
  
  <pre><code>&lt;input class="so" name="Name" value="bob"&gt;&lt;/input&gt;
  &lt;input class="so" name="LastName" value="Feyzi"&gt;&lt;/input&gt;
  &lt;input class="so" name="Email"&gt;&lt;/input&gt;
  &lt;input class="so" name="Address"&gt;&lt;/input&gt;
  &lt;input type="submit"&gt;&lt;/input&gt;
  </code></pre>
  
  <p><em>JavaScript :</em></p>
  
  <pre><code>var person={};
  var cars = document.querySelectorAll(".so");
  for (i = 0; i &lt; cars.length; i++) { 
    var elname = document.getElementByClassName('.so')[i].getAttribute('name');
    //var eln = document.getElementsByTagName("input")[i].getAttribute("name");
    var vala = document.querySelectorAll('.so')[i].value;
    //alert(vala);
    alert(elname);
  }
  </code></pre>
  
  <p>After I run the script I want the <code>person</code> <em>object</em> to be set with this data:</p>
  
  <pre><code>person {
      Name: "bob",
      LastName: "Feyzi",
      Email: "",
      Adderss: ""
  }  
  </code></pre>
  
  <h3><a href="http://jsfiddle.net/guyavunf/1/" rel="nofollow">JSFiddle</a></h3>