views:

40

answers:

1

i have the jquery ui button widget working w/ the following code.

$(.remove_img).button({ icons: { primary: 'ui-icon-cancel' } });

but if there isn't an image in place, on upload, i am appending a button with class .remove_img, so it isn't in the DOM on page load. is there a way to get it so that the added button will still trigger the same .button code?

i tried

$('.remove_img').live('click', function(event){
 $(this).button({
  icons: {
   primary: 'ui-icon-cancel'
  }
  });
 });

but it didn't get me anywhere.

A: 

live() should be exactly what you need. Can you do something very simple in the callback to verify whether it is getting bound or not? How are you generating the elements later? Are you using jQuery's append() to do it?

Using live and then append should work just fine, it's pretty much the most basic example of how to use live, so something else is going on here.

Adam Bellaire
i think it has to do with the binding? i'm just learning about that so i dont know. basically the button gets appended when the ajaxupload script completes. so there isn't a click to trigger things. trying to read about .trigger (and figure where to put it)
helgatheviking
also- when i use .live it doesn't work on the regular DOM version (which does exist in the DOM conditionally if there is an image that has been uploaded). ideally i'd like to not have to code that jquery UI effect twice.
helgatheviking