How to find the previous element of the specified element in jquery
<p>I'm trying to find the previous <code>img</code> element present before the specified element. But when I run my code it returns <code>undefined</code>.</p>

<p>My code is:</p>

<pre><code> $(document).on('keypress','#sendComment', function(e) {
    if(e.keyCode==13){
        var itemId=$('#findbefore').prev('.SharedImage');//
        console.log(itemId);
        var dataid=itemId.data('id');
        var dataalid=itemId.data('alid');
        var datashareid=itemId.data('shareid');
        var alt=itemId.attr('alt');
        alert(dataid +' '+dataalid+' '+datashareid+' '+alt);
    }
});
</code></pre>

<p>This was printing <code>Object[]</code> in console and <code>undefined undefined undefined undefined</code> in alert.</p>

<p>And my divs are :</p>

<pre><code> &lt;div id="S04" class="snew" style="display: block;"&gt;
 &lt;div class="author-image"&gt;&lt;/div&gt;
 &lt;span&gt;ajay shared the image xyz&lt;/span&gt;
 &lt;div class="s-content"&gt;
 &lt;div class="s-message"&gt;&lt;/div&gt;
 &lt;div class="shpicture"&gt;
 &lt;img class="SharedImage" width="100%" height="100%" data-shareid="1" data-alid="1" data-id="1" alt="xyz" src="data:image/jpeg;base64,"&gt;
 &lt;/div&gt;
 &lt;/div&gt;
 &lt;/div&gt;
 &lt;div class="SPcommentbox" id="findbefore"&gt;
 &lt;div class="comment"&gt;
 &lt;div class="commenter-image"&gt;&lt;/div&gt;
 &lt;div class="addcomment"&gt;
 &lt;input id="sendComment" class="commentbox" type="text" placeholder="Write a comment..."&gt;
 &lt;/div&gt;
 &lt;/div&gt;
 &lt;/div&gt;
</code></pre>

<p>I need to find the attribute values of <code>img</code>. When user press enter button.</p>

<p><strong>Note : I'm adding these divs with jQuery</strong></p>

<p>Please anyone help me to solve this ... Thanks...</p>
