I have a problem where im using javascript to change the href of the facebook like button to change the url to a new link based on new ajax video content the user can load on the webpage. I want to make it so they can like each video based on the current one they are watching. The href is swapping out beautifully and i declared a FB.XFBML.parse(document.getElementById("fbyoutubelike")); to refresh the like button. However nothing happens and I'm not sure what to do anymore. Does anyone have a clue as to how this can be accomplished?
1 Answer
FB.XFBML.parse probably won’t re-render the tag if it sees the iframe is already there …
Instead of just manipulating the href attribute content, remove the existing like button tag (<fb:like> or <div class="fb-like">) from the DOM, insert a new one – and then call FB.XFBML.parse.
5 Comments
Derek Rhode
<script> function urlSwapper(url){ //document.getElementById("fbyoutubelike").setAttribute("href", [url]); $("#youtubelike").replaceWith('<fb:like id="fbyoutubelike" class="fb-like" href="'+[url]+'" send="false" width="450" show_faces="false"></fb:like>').delay(1500, function() { FB.XFBML.parse; });; }; </script>C3roe
Are you using two different element ids in that code on purpose, or …?
Derek Rhode
yes youtubelike is the container div which houses the like button which has an id of fbyoutubelike
C3roe
OK, just seeing this now – maybe you should actually call FB.XFBML.parse if you want it to (re-)parse the document :-)
C3roe
You did not call it at all. C’mon, how are functions/methods called in JavaScript again? Not by just stating their name …