My JavaScript photo gallery dynamically loads images from an API onto the page when users click on a thumbnail. I want users to be able to leave Facebook comments on each image, so I've included a Facebook comments element on the page containing the gallery.
<div class="fb-comments" data-href="" data-num-posts="10" data-width="480"></div>
When the page initially loads and the gallery is populated, I set the data-href attribute of the comments element to the URL of the first image (e.g. ). If a user clicks on a different thumbnail, I update the attribute to reflect the URL of the selected image.
fbComments.attr('data-href', data.link + index);
FB.XFBML.parse();
I've read that using FB.XFBML.parse();
should refresh the Facebook comments. I added a comment to one image and then clicked on a thumbnail for a different image without a comment, but my initial comment is still visible. Any ideas on why this might be happening?
I've double-checked that the FB object is logged correctly in my JavaScript file and is available when called. The click event in my JS does update the data-href attribute appropriately. When I manually set a different data-href in the fb-comments element, the comments display correctly.