title: Use hasAttribute() get TypeError: hasAttribute is not a function
body: <p>I try to find out the number of <code>&lt;img&gt;</code> elements that do not have "style" attribute in a <strong>HTML</strong> file by using <strong>JavaScript</strong>.</p>
  
  <p>My solution: find out numbers of <code>&lt;img&gt;</code> tags as "<strong>imgCount</strong>", then get number of <code>&lt;img&gt;</code> tags with "style" attribute as "<strong>imgStyCount</strong>". After that, use "<strong>imgCount</strong>" minus "<strong>imgStyCount</strong>" to get the final result that I wish to know.</p>
  
  <p>However, something goes wrong. My browser keep told me</p>
  
  <blockquote>
    <p>TypeError: document.getElementsByTagName(...)[K].hasAttribute is not a function</p>
  </blockquote>
  
  <p>At the if statement.
  And the weird thing is, the <strong><em>alert(document.getElementsByTagName("img")[k].hasAttribute("style")</em></strong> show the if statement result is TRUE.
  How it can be like not a function and give the true value?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var imgCount = 0;
  
  var imgStyCount = 0;
  
  var result;
  
  for (k in document.getElementsByTagName("img")) {
  
    if (document.getElementsByTagName("img")[k].hasAttribute("style") == true) {
  
      alert(document.getElementsByTagName("img")[k].hasAttribute("style"));
  
      console.log("    &lt;img&gt; =: ", document.getElementsByTagName("img")[k].style);
  
      imgStyCount++;
  
    }
  
    imgCount++;
  
  }
  result = imgCount - imgStyCount;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;img height="150px" src="Http://flax.nzdl.org/images/ngf.jpeg" style="vertical-align:middle;margin-right:20px;" /&gt;
  &lt;img src="Http://flax.nzdl.org/images/abc.jpg" /&gt;
  &lt;img src="Http://flax.nzdl.org/images/fbc.jpg" /&gt;
  &lt;img src="Http://flax.nzdl.org/images/agc.jpg" /&gt;
  &lt;img src="Http://flax.nzdl.org/images/abt.jpg" /&gt;</code></pre>
  </div>
  </div>
  </p>