开发者

Dynamically add facebook like button using jquery

How can i dynamically add facebook like button using jquery? I'm planning to have a gallery and want to add开发者_JS百科 add like buttons under every image? I've tried this but it doesn't render anything: $('.share_button').append("(fb:like layout='button_count' font='tahoma')(/fb:like)") where share_button is a classname of div tag that will contain the like button.

Thanks in advance, Ivan


First of all, it should be:

$('.share_button').append("<fb:like layout='button_count' font='tahoma'></fb:like>")

Then, you should add this line:

FB.XFBML.parse($('.share_button').get(0));

However, I suggest you to use ID instead of class, or the codes above will parse all nodes containing class .share_button.


You also should have

xmlns:fb="http://www.facebook.com/2008/fbml"

and after you should parse FB tags that you add after page was loaded. It was previously answered here on SO

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜