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?
views:
60answers:
2
+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
2009-10-21 16:56:48
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
2009-10-21 17:30:42
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
2009-10-21 17:36:39
+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
2009-10-21 16:57:51