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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745418019a4626839.html
评论列表(0条)