title: Why doesn't adding loading="lazy" with JavaScript work to actually lazy load the images?
body: <p>I'm able to add the <code>loading=&quot;lazy&quot;</code> attribute on individual images, or with JavaScript and apply them all at once.</p>
  <p>But, when I do it with JavaScript, and then inspect the page, I see the images load on page load, but each image has the attribute attached.</p>
  <p><strong>Why does adding <code>loading=&quot;lazy&quot;</code> with HTML load the image lazily, but adding the attrib with JavaScript doesn't provide the lazy loading behavior?</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let img = document.querySelectorAll('img');
  for (let i = 0; i &lt; img.length; i++) {
    let images = img[i];
    images.setAttribute('loading', 'lazy');
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>img {
    max-width: 100%;
    height: auto;
  }
  
  .container {
    margin-top: 2000px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
    &lt;img src="https://images.unsplash.com/photo-1481349518771-20055b2a7b24"&gt;
    &lt;img src="https://images.unsplash.com/photo-1494253109108-2e30c049369b"&gt;
    &lt;img src="https://images.unsplash.com/photo-1494232410401-ad00d5433cfa"&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>