English 中文(简体)
Jquery UI button on items added after page load
原标题:

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.

问题回答

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.





相关问题
Using jQuery Plugins with Wordpress

Having a bit of trouble using jQuery plugins (Superfish, jQuery UI, etc) using Wordpress. Everything works fine in my plain non-Wordpress site, but Wordpress seems to conflict with JQuery. There must ...

Jquery TableSorter 2.0 - Revert Sort order

All, I am using the JQuery TableSorter Plugin. The table sorts fine for the selected columns. Consider that when the page loads, there is no sorting taking place. Now, if the table is sorted by one ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

热门标签