0

Not a duplicate. I've tried the suggested post, it still doesn't work.

I have a page which allows me to select some users from a list of available users which is listed in a div

<div id='external-events'>
      <h4>Available users</h4>
      <div id="emyevent">
          <div class='fc-event'>Roddy</div>
          <div class='fc-event'>Robert</div>
          <div class='fc-event'>Bob</div>
          <div class='fc-event'>John</div>
    </div>
</div>

When the user clicks on one of the user in the div elements it moves into another section as a selected user and removes it from the list of available users

<div id='internal-events'>
    <h4>Selected</h4>
    <div id="imyevent">
    </div>
</div>

I use the following code to do this

$("#external-events .fc-event").click(function(){
    var title = $(this).text();
    $("#imyevent").append("<div class='fc-event' style='margin: 10px 0;cursor: pointer;'>"+title+"</div>");
    $(this).remove();
});

The issue I have is now, if the person made a mistakes he/she clicks on the selected user and the selected user chosen returns to the available user section. I thought it would have been as simple as using this

$("#internal-events .fc-event").click(function(){
    var title = $(this).text();
    $("#emyevent").append("<div class='fc_event' style='margin: 10px 0;cursor: pointer;'>"+title+"</div>");
    $(this).remove();
});

But I'm obviously doing something wrong since it isn't work. Can somebody help please.

Thanks, Roddy

  • Not a duplicate. I've searched for several hours before I posted this. It a specific issue on the code I've written, I've checked the suggested post but it doesn't help. Please unmark as duplicate. – Roddy Dairion Sep 25 '15 at 13:55
  • It _is_ the same issue, and the solution provided there does solve it. If it doesn’t for you, then you did either not implement it correctly, or perhaps you have not even understood the issue properly yet. Feel free to research “event delegation” some more, and also look at the documentation for jQuery’s `.on` – CBroe Sep 28 '15 at 07:53

0 Answers0