views:

60

answers:

2

My problem: after load some element via ajax, i bind some on-click function, but when user will load few times that same element, binded action will be repeat (not replace, at least that it looks like). I tried unbind, or click(function(){return false;}); but that complete remove clic action from element...). What is standard solution of that kind of problem?

+5  A: 

For most events you can use live() (jQuery 1.3+):

$("td").live("click", function() {
  // do stuff
});

This will bind a click event to <td> elements that come into existence after you run this code as well.

This is a much cleaner solution than trying to bind/unbind and ensure you don't have the same event bound twice to a particular element.

cletus
Thx, +1 and `correct answer`, but a little problem still is: with `not` it suppose to don't work... `$("...").not("sada").live("click", func...`.
Rin
That's going to be a little more problematic. What exactly are you trying to do? I can perhaps suggest a way that'll work.
cletus
+1  A: 

if you're using jQuery 1.3.2, you can use $('').live('click', function() {}); to have any elements that match that selector have the action. It keeps the event around even with new elements.

Agent_9191
thx +1 :) (lalala 15 chars)
Rin