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

  • Home
  • SEARCH
  • 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 8872521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:14:25+00:00 2026-06-14T18:14:25+00:00

I am working with jQuery. Here I have an html page. In the html

  • 0

I am working with jQuery. Here I have an html page. In the html I have two div’s. The first div contains an image, a name and a price. Right now we have to move the image to another div which is empty. Here I move the image form the first to the second div. The problem is to find the id of image. I need to find the ID of the moved image.

Here is my HTML.

   <div>
    <span class="span1">
        <img src="~/Images/galaxy.jpeg" />
    </span>
    <span class="span1">1232</span>
    <span class="span2">Cell Phone</span>
    <span class="span1">3500</span>
    <a href="#" class="pull-right"><i class="icon-plus" onclick="AddToCart(this)" id="btnid"></i></a>
  </div>
  <div class="span7" style="border:1px black" id="separat"></div>

And My jQuery code:

$(function() {
    AddToCart(this);
});

function AddToCart(obj) {
    var val = 0;
    var $this = $(obj).closest('div');
    var img = $this.find('img');
    var image = img;
    $('#separat').append(img);
}​

Here I am adding the image to the second div. I need to get the image ID of the moved or added.

  • 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-14T18:14:26+00:00Added an answer on June 14, 2026 at 6:14 pm

    You need to specify an ID attribute to begin with and let’s not use an onclick attribute:

        <div>
          <span class="span1">
          <img src="http://blog.codepen.io/wp-content/uploads/2012/06/Button-Black-Small.png" width=20 id="galaxy" />
          </span>
          <span class="span1">1232</span>
          <span class="span2">Cell Phone</span>
          <span class="span1">3500</span>
          <a href="#" class="pull-right"><i class="icon-plus" id="btnid">+</i></a>
       </div>
      <hr>
       Cart:
       <div class="span7" style="border:1px black" id="separat"></div>
    

    And update your jQuery:

       function AddToCart() {
         var img = $(this).closest('div').find('img').first();
         var image_id = $(img).attr('id');
         var newobj = $('<div>');
         newobj.prepend(img.clone());
         newobj.append('<span>' + image_id + '<span>');
         $('#separat').append(newobj); 
       }
    
       $(function(){
         $('.icon-plus').click(AddToCart);
       });
    

    SEE:

    https://gist.github.com/4124585

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on jQuery here I have a html page. In the html
Hi all iam working on jquery here i have a html page. in the
I'm working with a dynamic DOM here, and have called the jQuery UI datepicker
Still working through JQuery to get data and repopulate portions of a page. Right
I have a trouble with selecting element attributes with jquery here is my HTML:
I have two pages: index.html and main.html When i set the main.html page to
I am having a WTF moment here. I have been working with jQuery since
I have a HTML page which is divided into two frames. Separate web sites
In an HTML page, I have three blocks: two textboxes and one inline SVG,
I have a FireWorks-generated HTML page and I added some jQuery to it for

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.