>From what you described, you are adding the element after you have bound
an event.
So your code is really doing:
1. bind function to click event of some element
2. add some element to the dom
 
you can clearly see the event wont get attached to the element.
 
you'll either have to call the code again after the element is added;
or i would suggest looking at "event delegation"
 

________________________________

From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Matt Quackenbush
Sent: Monday, 21 January 2008 1:45 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Manipulate Element After Being Added to DOM


Hello,

I'm working on a form that allows the user to click an "Add an Item"
button in order to add another item to their order.  When this button is
clicked, I have jQuery add another couple of fields to the form, so the
user can input the data.  Along with the added form fields, a "Remove
This Item" button is also added to the DOM.  All of this portion works
nicely.  It's the reverse that I'm having trouble with. 

What I'm trying to do is to call empty() on the container of the clicked
"Remove This Item" button (actually, an anchor).  I am getting no errors
at all in FireBug, but when the anchor is clicked, the jQuery script is
completely ignored and the browser follows the link. 

So, my question is: does jQuery support manipulation of an element that
has been added to the DOM via Javascript?  I would assume that it does,
but I'm not understanding why my "remove" function (code below) is being
ignored. 

$("a.remove-item").click(function() {
    var splt = $(this).attr("id").split("-");
    var n = splt[1];
    $("#container-" + n).empty();
    return false;
}); 


Thanks in advance,

Matt



NOTICE
This e-mail and any attachments are confidential and may contain copyright 
material of Macquarie Group Limited or third parties. If you are not the 
intended recipient of this email you should not read, print, re-transmit, store 
or act in reliance on this e-mail or any attachments, and should destroy all 
copies of them. Macquarie Group Limited does not guarantee the integrity of any 
emails or any attached files. The views or opinions expressed are the author's 
own and may not reflect the views or opinions of Macquarie Group Limited.

Reply via email to