Why FB.XFBML.parse() doesnt render my plugin?

markzzz picture markzzz · Oct 11, 2012 · Viewed 10.2k times · Source

My code :

<a id="render-me" href="javascript:void(0);">Render me</a>
<div id="social-facebook"></div>​

$('#render-me').click(function (e){
    e.preventDefault();

    $('#social-facebook').html("<fb:like id='button-facebook' href='http://www.google.com' send='false' layout='button_count' width='450' show_faces='false'></fb:like>");
    FB.XFBML.parse(document.getElementById('button-facebook'));    
});

I click, but the button is not rendered. Where am I wrong?

Answer

Marco Palermo picture Marco Palermo · Nov 25, 2012

You have to specify a node already in DOM. So, you can't use:

FB.XFBML.parse(document.getElementById('button-facebook'));

use instead:

FB.XFBML.parse(document.getElementById('social-facebook'));

and it will work fine ;)