Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-27-2013, 01:09 AM   PM User | #1
itxtme
Regular Coder

 
Join Date: Jun 2009
Posts: 105
Thanks: 3
Thanked 17 Times in 17 Posts
itxtme is an unknown quantity at this point
Jquery Append and then remove

I am using the append method to add html to the page. This works perfectly, however when appending that html I also need to append a remove button. It will append the button however it does not work, it wont remove the element.

If I hard code the remove button in it works, but when appeneded nothing happens.

I have a JSfiddle,

When you click on 'Refund Item' the words 'Hello' followed by 'Take it' appear. The take it when clicked should remove the 'Hello' element, but it does not. Ny ideas??

Last edited by itxtme; 02-27-2013 at 01:09 AM.. Reason: add fiddle
itxtme is online now   Reply With Quote
Old 02-27-2013, 01:43 AM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
adding a simple click listener to an element will only work if the element exists at the time that the code is run. To add a listener to an element that doesn't exist yet, one solution is to delegate the event:

Code:
 $("#there").on("click"," #remove_1", function () {
	 $('.take').remove();
 });
xelawho is offline   Reply With Quote
Old 02-27-2013, 02:32 AM   PM User | #3
itxtme
Regular Coder

 
Join Date: Jun 2009
Posts: 105
Thanks: 3
Thanked 17 Times in 17 Posts
itxtme is an unknown quantity at this point
fantastic, thanks for that!
itxtme is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:54 PM.


Advertisement
Log in to turn off these ads.