aVC
aVC

Reputation: 2344

jquery bind an ajax loaded element

I am trying to use a rating plugin which has the following bind command.

$("#rateit10b").bind('over', function (event, value) { 
    $(this).attr('title', tooltipvalues[value - 1]); 
});

The html is

<div class='rateit' id='rateit10b' data-rateit-step='1' >
            </div>

But I am loading the html via ajax. The jquery does nt seem to work. Can I use .live() with this?

Upvotes: 1

Views: 713

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191789

Use .on, delegation style:

$(document).on('over', '#rateit10b', function (event, value) {

Several things:

  1. Don't use .live. It's removed in jQuery 1.9
  2. Use a more specific selector to bind with than document if you can
  3. Is over an event type? Do you mean mouseover?

Upvotes: 2

Related Questions