spider-virus
spider-virus

Reputation: 49

How to delete an Added image from the div using jQuery?

I am working on jQuery here I have a html page. In the html I have two div's; the first div contains image, name, and price right now we have to move image to another div which is empty div

Here I had done to (move) add image form first to second. Now I want to delete the image from the second div using jQuery which is added image

Here is my markup and code:

<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 this is my jQuery code:

function AddToCart() {
        var img = $(this).closest('div').find('img').first();
        var price = $(this).closest('span2').clone();
        alert(price);
        var image_id = $(img).attr('id');
        var newobj = $('<div>');
       newobj.prepend(img.clone());
       newobj.append('<span>' + image_id + '<a href="#"><i class="icon-remove" <span></i></a>');
         alert(image_id);        
        $('#separat').append(newobj);
}

$(function () {
        $('.icon-plus').click(AddToCart);
});

This is my remove function

function RemoveCart() {
    //var img = $this.find('img').RemoveCart();
    $(".separat").clone().find("img").remove();
}

$(function () {
    $('.icon-remove').click(RemoveCart);
});

Here I am adding image to the second div I need to get delete the image from second div I have a icon-plus image button which from (Separat) div When I click on it it should remove from the div

Please help me to do this thanks in advance

Upvotes: 1

Views: 4343

Answers (1)

djakapm
djakapm

Reputation: 175

You can just use

img.remove();

Upvotes: 1

Related Questions