Link to home
Start Free TrialLog in
Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America

asked on

jQuery form cloning extras

Got the code here: http://jsfiddle.net/vdUuy/11/

How would I add the following span to the participants div and add the click handler so it would remove the participant added?

<span class="remove_participant">&nbsp;</span>

Open in new window


Also, it looks like the click handler isn't working, don't know why.
Avatar of moagrius
moagrius
Flag of United States of America image

change this:

 p.text(o.fname + ' ' + o.lname);
        p.data('index', i);
        p.click(deleteParticipant);
        list.append(p);

to this

        var s = $('<span>');
        s.addClass('remove_participant');
        s.data('index', i);
        s.click(deleteParticipant);
        p.append(s);
        list.append(p);

I tried updating the fiddle, but there are some other issues (e.g., there's no element with id of "add-participant")

you also want to use e.preventDefault() in any click action triggered by a link to stop the default behavior

someLink.click(function(e){
  // do stuff..
  e.preventDefault();
});
just to clarify - the listParticipants function should now look like:

function listParticipants(){
    list.empty();
    for(var i = 0, l = participants.length; i < l; i++){
        var o = participants[i];
        var p = $('<p>');
        p.text(o.fname + ' ' + o.lname);
        var s = $('<span>');
        s.addClass('remove_participant');
        s.data('index', i);
        s.click(deleteParticipant); 
        p.append(s);
        list.append(p);
    }  
}

Open in new window

Avatar of Eddie Shipman

ASKER

The fiddle has the add-participant id on the button now but I can't understand why the remove-participant doesn't have the image. I see the styling in FB but not see the image.
i don't think you linked the right fiddle, then - that one definitely does not have a button with id of add-participant...  and the button doesn't work...  can you double check the link?
I didn't know it changed the URL when you updated.
try this one.
http://jsfiddle.net/S24wu/13/
ASKER CERTIFIED SOLUTION
Avatar of moagrius
moagrius
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Saved my butt, again, thanks.
glad i could help.  i'm out for the day, but i'll check in again tomorrow if anything else comes up for this.