Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 285
markzzz Avatar asked Dec 07 '22 11:12

markzzz


2 Answers

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 ;)

like image 165
Marco Palermo Avatar answered Dec 09 '22 00:12

Marco Palermo


Try to add this markup

<div id="fb-root"></div>

in bottom of page and make sure you are added FB script. Please have a look the image

enter image description here

Please follow these steps you will able to solve you problem.

For more info please go through this link https://developers.facebook.com/docs/reference/plugins/like/

like image 33
Soarabh Avatar answered Dec 08 '22 23:12

Soarabh