0
$('.negative').on('click',function() {
  var saveImg = $(this).parents('.img_listing_long').find('img').clone();
  $(list).append(saveImg);
});

If the element is already present in the list then it shouldn't be cloned.

David
  • 208,112
  • 36
  • 198
  • 279
Mahima
  • 1
  • 1
    Do you have something in each image element which uniquely identifies it? e.g. an ID or a data attribute or something? We need a bit more context about your HTML, I think. – ADyson Jul 21 '22 at 11:36

1 Answers1

1

Update it:

$('.negative').on('click',function() {
  if( $(list).find('img').length == 0 )
  {
     var saveImg = $(this).parents('.img_listing_long').find('img').clone();
     $(list).append(saveImg);
  }
});

Or put the class on img tag like class name "myimage" then:

$('.negative').on('click',function() {
      if( $(list).find('.myimage').length == 0 )
      {
         var saveImg = $(this).parents('.img_listing_long').find('img').clone();
         $(list).append(saveImg);
      }
    });
Ws Memon
  • 107
  • 7