javascript - Run jQuery ready block again after ajax loaded? - Stack Overflow

I'm not sure if I'm asking the right question here, but basically I'm inserting html wit

I'm not sure if I'm asking the right question here, but basically I'm inserting html with an ajax request:

// data-active_chart
if ($("#charts").attr("data-active_chart") == "barchart") {
  $.ajax({
    url: $("#charts").attr("data-path") + "/barchart",
    success: function(data) {
      $('#charts').html(data);
      console.log('Load was performed.');
    }
  });
}

And my HTML is something like:

<div id="charts" data-active_chart="barchart" data-path="">

</div>

But the point is I need jQuery to be aware of the updated DOM, like I need my tool tips and such to work in the HTML that's been inserted, along with a bunch of other things in the inserted HTML all need to respond to JS, how do I do this in a best practices way?

I'm not sure if I'm asking the right question here, but basically I'm inserting html with an ajax request:

// data-active_chart
if ($("#charts").attr("data-active_chart") == "barchart") {
  $.ajax({
    url: $("#charts").attr("data-path") + "/barchart",
    success: function(data) {
      $('#charts').html(data);
      console.log('Load was performed.');
    }
  });
}

And my HTML is something like:

<div id="charts" data-active_chart="barchart" data-path="http://example./something">

</div>

But the point is I need jQuery to be aware of the updated DOM, like I need my tool tips and such to work in the HTML that's been inserted, along with a bunch of other things in the inserted HTML all need to respond to JS, how do I do this in a best practices way?

Share Improve this question asked Mar 18, 2011 at 21:27 JP SilvashyJP Silvashy 48.6k50 gold badges153 silver badges230 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 6

If you need to bind events that will occur after the DOM has changed use jQuery live!

If the existing handlers were attached using jQuery live, you should be good to go after updating the DOM.

You will have to test that this is the case though; it could be that certain libraries you are using may have been using .click() or .hover() directly in which case you will need to reinitialize the handlers or libraries after updating the dom.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745418019a4626839.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信