Results 1 to 3 of 3

Thread: [RESOLVED] "Re-Bind" click events

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Resolved [RESOLVED] "Re-Bind" click events

    I build up a dynamic list of items with a "view" link at page load.
    The "click" event of these are as follows (works fine)
    Code:
    $('.btnEditRequest').click(function () {
        var link = this;
        ViewRequest(link.id);
    });
    Inside "ViewRequest" I can let the user edit the item and on that's success I re-create my list using an ajax post and json.
    However,after doing so, my "click" event for $('.btnEditRequest') won't fire anymore.

    I remember I have to "bind" it ,but now not sure about the syntax again:

    After re-building my list, I should do something in the line of (wrong syntax) the following, no?
    Code:
    $('.btnEditRequest').bind('click', function () {
        var link = this;
        ViewRequest(link.id);
    });


  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: "Re-Bind" click events

    Sounds like you might want to use either live() or delegate() - either will allow you to assign an event handler to a set of elements matching a criteria presently (at page load) or in the future (after an AJAX request has altered the DOM).

    Edit: looks like live() is now deprecated in favor of on()

  3. #3

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: "Re-Bind" click events

    That worked, doing the "on" thing right after building up the list. Thanks!
    http://www.andismith.com/blog/2011/11/on-and-off/


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width