H.HISTORY
H.HISTORY

Reputation: 518

jQuery: append and remove Elements?

I'm trying to append items and then have the option to remove them.

I can simply append the elements using append() in jquery which works fine.

However, I have a problem removing them USING remove().

to demonstrate this, I've created this fiddle:

http://jsfiddle.net/q3Le48o8/1/

If you click on the book image, you'll see the elements are being appended properly but when I click on the elements, they are not being removed at all!

Could someone please advise on this issue?

Upvotes: 0

Views: 50

Answers (2)

Sorav Garg
Sorav Garg

Reputation: 1067

Hello i have fixed your issue please check below link 

http://jsfiddle.net/q3Le48o8/2/

Upvotes: 1

Akram Saouri
Akram Saouri

Reputation: 1169

change your code to :

/////append items//////////
$('.addons').click(function() {
   var names2 = $(this).attr('data-name');
   $('.Slevel').append('<span class="pricetag">'+names2+'</span>');
});


$(document).on('click', '.pricetag',function(){
    $('.pricetag').remove();
});

Upvotes: 0

Related Questions