First post here. Recently I have been spending a lot of time learning JavaScript. I've been using the jQuery library and I just now learned that ajax calls will NOT work on portions of the page which are dynamically loaded (without refreshing). Naturally, I need ajax functionality for these posts as well. I need help understanding the best way to work around this annoyance.
Yes, I have read and saw what was said in the jQuery FAQ, but to me it was vague and non-informative, but did provide some basic information: http://docs.jquery.com/Frequently_Asked_Questions#Why_do_my_events_stop_working_after_an_AJAX_request.3F
Specifically, I am making a user-profile page, similar in concept to a facebook profile page. Users post comments to other users, and new comments are automatically loaded onto the page using jQuery's ajax functionality. Each comment has buttons such as "Delete", "Like", "Reply", etc which work great with ajax, but they do not work at all for comments that are automatically loaded onto the page...
I found out about the delegate() method, which I understand is how some people get past this. So far all that I have in my code is this:
$(document).delegate('img', 'click', function(){
alert('test'); //Stub
});
This works, but THE PROBLEM IS I already have jQuery methods which I wrote to handle every single one of my ajax calls. I can't figure out how to use delegate to call the jQuery code blocks that I already wrote. Is it possible? For example, this loads a comment box underneath the comment of which the user clicked the "Reply" button:
$('img.wallpost_reply').click(function(){
$(this).closest('div.wallpost').find('div.wallreply').slideDown('fast'); //Toggle the window
$(this).closest('div.wallpost').find('textarea.wallpost_input').focus(); //Focus on the textarea
});
^^This is very simple block of code works perfectly, similar to many other small blocks of code which I have. This one gets called when the user clicks on the "Reply" image, like this:
<img class="wallpost_reply" style="cursor:pointer;" src="./images/reply.png" alt="Reply" />
How can I assign delegate() to link up with the jQuery code that I already wrote??? Is this even possible? I would rather not write completely new functions which have the same functionality, if possible.