I have a spreadsheet of data on my website, which is loaded in from a database, and the result looks something like this:
<table>
<tbody id="tbody">
<tr>
<td><button>Edit</button></td>
<td><button>Delete</button></td>
<td>First Name</td>
<td>Last Name</td>
...
</tr>
</tbody>
</table>
More content (rows) appear as the user scrolls down, and this is done with Ajax, like so:
$(document).ready(function(){
/*Get more clients on scroll*/
var clientCount = 33;
$(window).scroll(function(){
var leftToBottom = $(document).height() - $(window).height() - $(window).scrollTop();
if( leftToBottom == 0) {
clientCount = clientCount + 11;
$("#tbody").load("loadClients.php", {
clientNewCount : clientCount
});
}
});
});
However, each row of data has something like an edit button which opens a modal, a delete button, a multiple-delete-selection, etc. These are all manipulated through jQuery/JS.
This question gave me an idea of what to do, but I just couldn't apply it to my code: Running JQuery scripts on AJAX loaded content
Someone suggested using the ajaxComplete() function, but this means the jQuery code will only work after the ajax content has been completed (duh).
Aside from using the $(document).ajaxComplete() function, what can I do to apply my jQuery code to the new ajax content?
Problem is, the jQuery code won't work UNTIL the user scrolls down to get more content. So a user cannot edit, delete or select any data until they scroll down all the way to fetch the new content.
Pray, how can I apply the jQuery to both the content BEFORE the ajax call as well as AFTER the ajax call?
Currently I am including the jQuery script in both documents; the original document and the loaded-content. I'm sure this isn't the correct way to do it, but for now it is working.
P.S. the jQuery code contains many click events, preventDefaults, and other basic code to open and close modals.