如果 Facebook 评论为 0,则隐藏 div
Hide div if facebook comments are 0
我正在使用 Facebook 社交插件,一切正常。我想隐藏 "chat bubble"
的 div
如果
<span class="fb-comments-count" data-href="[article URL]"></span>
对于我主页上加载的每篇文章都是零,当然保留不为零的文章。
还有其他信息,我正在使用 "show more" 按钮加载其他使用 ajax 的文章。
我已经尝试对每篇文章使用 http://graph.facebook.com/ to get the information whether the address contains comments and it worked, but because I needed to ping http://graph.facebook.com/,我的页面加载时间很糟糕,所以我删除了它。
如果没有评论,范围将被赋予 class 'fb_comments_count_zero',因此您可以在样式表中将 class 设置为 display:none
创建一个函数迭代具有 "fb-comments-count" class 的跨度。并查找此跨度的文本是否为零。如果它为零,获取此 class(文章 DIV)的父项并使用 hide() 方法隐藏气泡 DIV。
https://api.jquery.com/each/
//for iterating .fb-comments-count
http://api.jquery.com/text/
//for getting get count from span
https://api.jquery.com/parent/
//to get the parent DIV by class or ID of span
http://api.jquery.com/hide/
//to hide the perticular div by class or ID.
Call this function every time you fetch the articles using AJAX.
例如
function yourCustomFunction() {
$('span.fb-comments-count').each(function(index) {
var count=$(this).text();
if(count==0) {
var parentDiv=$(this).parent('article.yourParentDivClass');
parentDiv.find('.bubbleDiv').hide();
}
});
}
我正在使用 Facebook 社交插件,一切正常。我想隐藏 "chat bubble"
的 div如果
<span class="fb-comments-count" data-href="[article URL]"></span>
对于我主页上加载的每篇文章都是零,当然保留不为零的文章。 还有其他信息,我正在使用 "show more" 按钮加载其他使用 ajax 的文章。
我已经尝试对每篇文章使用 http://graph.facebook.com/ to get the information whether the address contains comments and it worked, but because I needed to ping http://graph.facebook.com/,我的页面加载时间很糟糕,所以我删除了它。
如果没有评论,范围将被赋予 class 'fb_comments_count_zero',因此您可以在样式表中将 class 设置为 display:none
创建一个函数迭代具有 "fb-comments-count" class 的跨度。并查找此跨度的文本是否为零。如果它为零,获取此 class(文章 DIV)的父项并使用 hide() 方法隐藏气泡 DIV。
https://api.jquery.com/each/
//for iterating .fb-comments-count
http://api.jquery.com/text/
//for getting get count from span
https://api.jquery.com/parent/
//to get the parent DIV by class or ID of span
http://api.jquery.com/hide/
//to hide the perticular div by class or ID.
Call this function every time you fetch the articles using AJAX.
例如
function yourCustomFunction() {
$('span.fb-comments-count').each(function(index) {
var count=$(this).text();
if(count==0) {
var parentDiv=$(this).parent('article.yourParentDivClass');
parentDiv.find('.bubbleDiv').hide();
}
});
}