-
Dec 23rd, 2011, 04:19 PM
#1
Thread Starter
Hyperactive Member
[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);
});
-
Dec 24th, 2011, 03:08 AM
#2
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()
-
Dec 24th, 2011, 08:35 AM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|