.live() working on new elements but not existing elements

So i’ve got a form that adds an element onto the page. This is working. When I try to remove said elements, that works. But the same ‘delete’ button doesn’t work on elements not generated by javascript.


	function destroyQuickTask() {
		$.post($(this).attr("href"), null, null, "script");
		return false;
	}
	$('a.destroy_quick_task').live('click', destroyQuickTask);	

Is there something wrong with the way I’m using .live()? It basically is saying 'pay attention to all a.destroy_quick_task elements that exist now AND in the future, right? Seems like it’s fine with future elements and can’t deal with existing ones.

Just FYI the .live() event will work on all new AND existing elements as stated in the jquery documentation:

Oh, really? But doesn’t seem to work for me.
I have to call bind() in $(document).ready.

the live() function IS in a .ready function. still doesn’t work as advertised (on THIS project). Works as should on another project, that’s why i’m confused.

Just FYI the .live() event will work on all new AND existing elements as stated in the jquery documentation:

Decription: Attach a handler to the event for all elements which match the current selector, now or in the future.

I would recommend (if you haven’t already) adding your live call within a $(document).ready call.

Good luck

so is there a function that will work on existing elements AND new elements? Kinda thought live served that purpose, it was explained to me as so…

I think no.
Just call bind() for existing elements after page loading.
Then .live() for new elements in some event, eg. click event.

Yes, .live() works on new elements only.
If you need attach function to existing elements, use .bind() instead.

so is there a function that will work on existing elements AND new elements? Kinda thought live served that purpose, it was explained to me as so… 

“Find all elements on the website with class name “destroy_quick_task”, and add the onclick event to fire the destroyQuickTask function AND also add this same onclick event to all elements with class name “destroy_quick_task” that do not exist but might be created in the future.”