Search code examples
jquerybindlive

Dynamic Element not responding to .Live() function


I have a script that generates a list of elements; spans. I have scripts that move them around in the DOM hierarchy, to target divs and such, using .appendTo(). This following script won't work on the newly moved object, even though I'm using .live().

    var User = 0;
    $(".List span").live('dblclick', function(e){
        e.stopPropagation();
        User = $(this).attr('class').match(/Usr1/g) ? 1
             : $(this).attr('class').match(/Usr2/g) ? 2
             : null;
        $(this).prependTo("#List_" + User); 
    });

To clarify: I click a span; it moves to .List. I dblclick the span in .List; nothing happens. It should move to #List_*. The spans already in .List do move if I dblclick them.

Why doesn't the new guy move?


Solution

  • I reformulated the problem script, and it all works now. Thanks for letting me know about .on(), I'll look into it.