dilip
answered Apr 28 '23 00:00
If you want to run a jQuery function after an AJAX content load, you can use the . ajaxComplete () method in jQuery.
The . ajaxComplete () method is triggered when an AJAX request completes. You can use it to execute a function after the content has been loaded via AJAX.
Here's an example:
<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);
}
});
});
$(document).ajaxComplete(function() {
console.log('Content loaded via AJAX');
});
</script>
In this example, we use the . ajaxComplete () method to execute a function after any AJAX request completes. The function will be executed after the content of the #content element has been updated via AJAX.
You can replace the console.log statement with your own custom code to perform any actions that you want to take after the AJAX content has been loaded.