I’m trying to load the comment form dynamically into their corresponding posts. What I have so far works for the first 6 posts that are loaded on the initial load. It’s after the initial load that I’m running into problems. I need to be able to get this code to work on the remaining posts that are paginated and shown with an infinite scroll event. Any help would be greatly appreciated.
Cheers,
Mike
Commenform div in comment.php
<div id="commentform-<?php the_ID(); ?>" rel="<?php the_ID(); ?>" style="display: none"></div>
Comment form being called for in shortcodes.php
$output.='<div id="swap_comments-'.get_the_ID().'"rel="'.get_the_ID().'">'.comments_template('/comment.php').'</div>';
Comment form being handled in plugins.js
jQuery(window).ready(function() {
var commentscon = jQuery("div[id^='commentform']");
jQuery("div[id^='swap_comments']").append(commentscon);
jQuery.each(jQuery("div[id^='swap_comments']"),function(){
var CurrectDiv=jQuery(this);
CurrectDiv.find('div').filter(function(){
if(jQuery(this).attr('rel')==CurrectDiv.attr('rel'))
{
jQuery(this).show();
}
});
});
});
Use jquery .on() which has replaced .live()
http://api.jquery.com/on/
You have to use live function to assign function to dynamicly added elements.