How to get images alt using jquery?
<p>I'm trying to add data-title and data-lightbox and get Images alt inside.</p>

<p>the problem is, i have a similar outputs, from first image alt only!</p>

<p>How can we fix it?</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>jQuery(document).ready(function($) {
  var imagesalt = $('.box a img').attr('alt');
  $(".box a").attr("data-title", imagesalt);
  $(".box a").attr("data-lightbox", imagesalt);
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
&lt;div class="box"&gt;
  &lt;a href="#"&gt;
    &lt;img src="img1.jpg" alt="Text 1"&gt;
  &lt;/a&gt;
  &lt;div class="img-block"&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="box"&gt;
  &lt;a href="#"&gt;
    &lt;img src="img1.jpg" alt="Text 2"&gt;
  &lt;/a&gt;
  &lt;div class="img-block"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="box"&gt;
  &lt;a data-lightbox="text 1" data-title="text 1" href="#"&gt;
    &lt;img src="img1.jpg" alt="Text 1"&gt;
  &lt;/a&gt;
  &lt;div class="img-block"&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="box"&gt;
  &lt;a data-lightbox="text 1" data-lightbox="text 1" href="#"&gt;
    &lt;img src="img1.jpg" alt="Text 2"&gt;
  &lt;/a&gt;
  &lt;div class="img-block"&gt;&lt;/div&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>I tried writing the code more than one way, but not useful</p>

<p>Thanks</p>