Your problem is when you call the jQuery, if you call it on $(document).ready()
you will run into trouble as on $(document).ready()
you have not added the content. This is because JavaScript is asynchronous.
Here is a simple solution:
$.get('page-page-to-post.php').done(function(data) {
// jQuery for dynamically called content
});
This way you add the content, and then you add jQuery functions. I ran into this problem a while back, I was thinking of JavaScript like CSS. CSS is constantly being called.
Another way you is to add a callback function. This is useful if you want to add actions to the dynamically added content from a separate script and it reduces code bloat.
// main.js
var myApp = {
load: function(callback) {
$.get('page-page-to-post.php').done(function(data) {
callback();
});
}
}
Now, you can call this function like you would $(document).ready()
//new script
myApp.load(function() {
// jQuery / JavaScript to attach to dynamically loaded content
});