1

After adding a new DOM element after a ajax request, the click event for the newly added item doesn't work.

I tried to first unbind then bind, but I get an error.

$(".someclass").unbind("click", someEvent);
$(".someclass").bind("click", someEvent);

Am I doing something wrong here? (in theory)?

mrblah
  • 99,669
  • 140
  • 310
  • 420
  • Can you post the code that adds this element to the DOM? hgimenez gives a valid alternative (to use the live function), but what you're trying to do should work without issue. – David Andres Sep 24 '09 at 22:46

1 Answers1

1

Use live() instead of bind().

$('.someclass').live('click', someEvent)
hgmnz
  • 13,208
  • 4
  • 37
  • 41
  • I've never seen live() make a page laggy, I would test it out. If it does for you then you have way too many elements with a class of .someclass ;). Also, see this thread: http://groups.google.com/group/jquery-en/browse%5Fthread/thread/432a0d9caae734db – hgmnz Sep 25 '09 at 03:58