← Return to PHP Web Museum
Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthoraaronw
    • CommentTimeSep 20th 2008
     
    I'm loading table rows with Ajax and my click handlers don't work on the new rows. I know about the livequery plugin. Is that the right approach, or is there a better way?
    • CommentAuthorfloatleft
    • CommentTimeSep 21st 2008
     
    Event delegation: one handler on the table, check the target.

    $('#results').click(function(e) {
    var row = $(e.target).parents('tr:first');
    if (row.length) { ... }
    });

    The handler stays on the table, so rows added later work without rebinding.
    • CommentAuthoraaronw
    • CommentTimeSep 21st 2008
     
    Way better than rebinding after every load. Thanks.
    • CommentAuthorjbaker
    • CommentTimeSep 22nd 2008
     
    Also way faster with big tables. One handler instead of 500.