Search code examples
jquerymobilemobile-safari

jquery .appendTo() on mobile devices


I was wondering about something. I am using .appendTo() to send an item to another list once clicked using jquery. However, once the .appendTo() has occured I lose all other events on the item in the new list. The interesting part is that this only occurs on tested mobile devices (iPad, iPhone, etc.). Does anyone know why this is occuring?

I am going to add that I need the item that has .appendTo() applied to hold gesture events. These are being lost as well, once the .appendTo() is applied. Can jquery .on() hold gesture events?


Solution

  • It depends how you're binding your click events in the first place. Not sure why it would only affect mobile, but I assume that, once moved to another container, you have a different instance of the element without its events. Have you tried monitoring bubbled events using JQuery .on()? E.g.

    $(body).on('click', '.itemInList', function() { ... });
    

    This is going to handle click events for both current elements and any future-created elements.