How to get next index value in jquery
<p>I want to get the next index value in each loop, if index is last(here it is 2), take first index value.</p>

<p>So I tried the following code but not working.</p>

<pre><code>keyword = 'on';
var nextitem = '';
$(".clsiteration").each(function(index, el) {
    if ($(this).attr("src").toLowerCase().indexOf(keyword.toLowerCase()) &gt; 0) {
        if (index == 2)
            nextitem = $(this).first().attr('data-val');
        else
            nextitem = $(this).next().attr('data-val');
    }
});
</code></pre>

<p>HTML</p>

<pre><code>&lt;div&gt;
        &lt;img src="img_off.jpg" class="clsiteration" data-val="k1" &gt;
        &lt;img src="img_on.jpg" class="clsiteration" data-val="k2" &gt;
        &lt;img src="img_off.jpg" class="clsiteration" data-val="k3" &gt;
&lt;/div&gt;
</code></pre>

<p>How can I get next index value ? Thanks</p>