title: How to get index value of image using jquery?
body: <p>Hi all i am working on jquery i need to avoid adding multiple images  i had written the code here but </p>
  
  <p>always i am getting index value of image is -1 and always if condition fires i dong some thing wrong 
  could u plz help me to do that thanks in advance</p>
  
  <p>Here is the code for the first div</p>
  
  <pre><code>&lt;div&gt;&lt;span class="span1"&gt;
  &lt;img width="30" hieght="30" name="productimage" src="http://panther:805/Computers.jpg"&gt;&lt;/span&gt;
  &lt;span class="span1"&gt;Black_xxl_Slim&lt;/span&gt;
  &lt;span class="span1"&gt;1&lt;/span&gt;
  &lt;a class="pull-right" href="#"&gt;&lt;i onclick="Add(this)" class="icon-plus"&gt;&lt;/i&gt;&lt;/a&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p>Here is the code for the second div:</p>
  
  <pre><code>&lt;div class="span6" id="separat"&gt;
              &lt;ul class="thumbnails pre-scrollable" id="productbundles"&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>here my code follows </p>
  
  <pre><code>  function Add(obj) {
             var addedImagesArray = [];
             var img = $(obj).closest('div').find('img').first();
  
           var image_src = $(img).attr('src');
          var newobj = $('&lt;li class="span2" id="bunle' + id++ + '"&gt;&lt;a href="javascript: void(0)"&gt;&lt;img hieght=30  width=30 src="' + image_src + '" /&gt;&lt;/a&gt;&lt;h5&gt;' + "Name:" + name + '&lt;/h5&gt;&lt;span id="pric' + id + '"&gt;&lt;b&gt;' + "Price:" + price + '&lt;/b&gt;&lt;/span&gt;');
           if   (addedImagesArray.indexOf(image_src)) {
             alert("Image Already Added");//src present in the array so do nothing or show an alert..
           } else {
             $('#productbundles').append(newobj); //append the image
            addedImagesArray.push(image_src); ///add src to array
           }
        }
  </code></pre>
  
  <p>on above iam having two divs i am adding images from one div to another </p>
  
  <p>but  problem is i am getting -1 index value always plz help me to do this thanks in advance</p>