admin管理员组文章数量:1425666
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 02 Answers
Reset to default 6If 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.
本文标签: javascriptRun jQuery ready block again after ajax loadedStack Overflow
版权声明:本文标题:javascript - Run jQuery ready block again after ajax loaded? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745418019a2657775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论