title: How to get the value of an attribute in Javascript
body: <p>I have this input line which I am trying to extract the text of the value attribute:</p>
  <pre><code>    &lt;input type=&quot;text&quot; class=&quot;card-input small-font&quot; 
  ng-value=&quot;paymentVia.typeDisplay&quot; readonly=&quot;&quot; value=&quot;Credit card&quot;&gt;
  </code></pre>
  <p>The function <code>getAttribute(&quot;class&quot;)</code> works fine and it returns <code>card-input small-font</code> but the function <code>getAttribute(&quot;value&quot;)</code> returns <code>null</code>. I tried .value as well but this returns an empty string.</p>
  <p>Does anyone know why this is happening?</p>
  <p>This is my JS:</p>
  <pre><code>function() {
     var x = document.getElementsByClassName(&quot;card-input small-font&quot;);
     var payment =x[18].value;
  
     return payment;
  }
  </code></pre>