frenchie frenchie - 1 year ago 97
jQuery Question

replacing with jquery.on() doesn't work

I have several textboxes that are added dynamically after an ajax call. These boxes are tied to event handlers with .live() that currently work fine. I want to replace that with the newer .on() function.

This is what I have

mouseenter: function () { .... },
mouseleave: function () { .... },
blur: function () { ... }

When I replace .live() with .on() it doesn't work; the textboxes don't display their normal behavior after they're added.

If I write
$('#MainDiv .MyTextBox').live({...
, where MainDiv is the top DOM element where all the action happens, nothing happens either.

What am I missing?


Answer Source

Heres the example they have, but with the delegate:

vs non-delegate:

This is why i hate the new on syntax.

In yours simply do:

  mouseenter: function () { .... },
  mouseleave: function () { .... },
  blur: function () { ... }
}, '.MyTextBox');

and it should work

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download