Best way to manage .click() and .delegate() on a page
Hi all,
I load a static page, inside this page there are links like this:
- <a href="some/path/here/with/id" class="update">Click</a>
With this function I can change the link value (Click) with a second value depending on ajax response.
- $('.update').click(function(event) {
- event.preventDefault();
- $.post('script.php', {}, function(data){
- // Depending on the value that data has i change the link:
- <a href="some/path/here/with/id" class="update">Clicked!</a>
- // Then I replace the link
- });
- }
Ok, the question starts here: When I replace the link .click() doesn't work anymore I need to use .delegate() that works pretty good.
I need to create two functions, one for each case (.click() and .delegate()) or is there (I'm sure there is, but I don't know) a better way to do that?