tags:

views:

64

answers:

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)?

+1  A: 

Use live() instead of bind().

$('.someclass').live('click', someEvent)
hgimenez
wont' that be slower? I don't want my pages to become laggy...
mrblah
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
hgimenez