Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9098839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:27:36+00:00 2026-06-17T00:27:36+00:00

I am working in jquery. I have written a script which adds an image

  • 0

I am working in jquery.
I have written a script which adds an image from a first div to a second div.
However, I don’t want it to be possible to add the same image twice.

Here is the code for the first div

<div><span class="span1">
<img width="30" hieght="30" name="productimage" src="http://panther:805/Computers.jpg"></span>
<span class="span1">Black_xxl_Slim</span>
<span class="span1">1</span>
<a class="pull-right" href="#"><i onclick="Add(this)" class="icon-plus"></i></a>
</div>

Here is the code for the second div:

<div class="span6" id="separat">
            <ul class="thumbnails pre-scrollable" id="productbundles">
            </ul>
        </div>

here is my jquery

function Add(obj) {
    var img = $(obj).closest('div').find('img').first();

    var image_src = $(img).attr('src');
    var newobj = $('<li class="span2" id="bunle' + id++ + '"><a href="javascript: void(0)"><img hieght=30  width=30 src="' + image_src + '" /></a><h5>'+"Name:" + name + '</h5><span id="pric' + id + '"><b>'+ "Price:"+ price + '</b></span>');
    $('#productbundles').append(newobj);
}

Adding the div works fine, but it allows the same item to be added twice.
How can I stop this from happening?
Thanks in advance for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:27:40+00:00Added an answer on June 17, 2026 at 12:27 am

    many ways to do this… you can add a class to the <img> which has been appended and check for that class..using hasClass.

    the way i am doing it is.. creating an array.. and pushing the src into the array and checking if the src is present in the array or not

    function Add(obj) {
      var addedImagesArray=[];
      var img = $(obj).closest('div').find('img').first();
    
       var image_src = $(img).attr('src');
       var newobj = $('<li class="span2" id="bunle' + id++ + '"><a href="javascript: void(0)"><img hieght=30  width=30 src="' + image_src + '" /></a><h5>'+"Name:" + name + '</h5><span id="pric' + id + '"><b>'+ "Price:"+ price + '</b></span>');
       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
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some jquery code to select the div which is grandchild of
I am just starting working with jquery and have encountered the following problem <div
I have jquery validation code which is working fine in ff but the same
I have been working with jQuery mobile 1.0.1. I have a page which drills
I have this JQuery code working however I need to know whether how to
I have a working script like this: jQuery(document).ready(function(){ $('.video-thumb img').bind('mouseover',function(){ var new = $(this).attr('src').replace(/default.jpg/,'1.jpg');
I have written a jQuery script to glow and then fade out similar to
Update :- My updated script is second one and which is working perfect (
I'm currently working on a jQuery solution where I want to load images from
I'm trying to write a jQuery script (I have never written one before and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.