Phpworker
answered Apr 28 '23 00:00
To call a jQuery function after an AJAX HTML content is loaded, you can use the success callback of the $.ajax method or the load method.
Here's an example using the $.ajax method:
<div id="content">
</div>
<button id="load-content">Load Content</button>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$('#load-content').click(function() {
$.ajax({
url: '/path/to/content',
success: function(response) {
$('#content').html(response);
yourFunction();
}
});
});
function yourFunction() {
console.log('Content loaded via AJAX');
}
</script>
In this example, we use the success callback of the $.ajax method to call a function yourFunction () after the AJAX content is loaded.
You can replace the console.log statement in yourFunction () with your own custom code to perform any actions that you want to take after the AJAX content has been loaded.