0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

<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>
Are you using two different element ids in that code on purpose, or …?
yes youtubelike is the container div which houses the like button which has an id of fbyoutubelike
OK, just seeing this now – maybe you should actually call FB.XFBML.parse if you want it to (re-)parse the document :-)
You did not call it at all. C’mon, how are functions/methods called in JavaScript again? Not by just stating their name …

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.