jQuery click() event not firing on AJAX loaded HTML: Solution and Explanation
Yes, I can help. You need to use event delegation to bind the click event to the dynamically loaded HTML elements.
For example, if you want to bind a click event to a button with class 'my-button' that is loaded dynamically, you would use the following code:
$(document).on('click', '.my-button', function() {
// code to handle click event
});
This code binds the click event to the document object and delegates it to any elements with class 'my-button' that are added dynamically.
Make sure to replace '.my-button' with the appropriate selector for your element.
原文地址: https://www.cveoy.top/t/topic/m8zB 著作权归作者所有。请勿转载和采集!