如何在点击(使用jQuery)后删除Facebook之类的按钮?
这是我的代码。单击“赞”按钮后,它会提醒“我只是点击了按钮”,但此行无效$(this).remove();
。如何删除它?
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function(e) {
FB.Event.subscribe('edge.create', function(response) {
$(this).remove(); // I used this to remove button after clicking, but not working
alert('I just clicked like button');
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if(d.getElementById(id)){return;}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
这是我的FB Like按钮:
<div class="fb-like" data-href="https://facebook.com/myPage" data-layout="button" data-action="like" data-show-faces="false" data-share="false" ></div>
答案 0 :(得分:3)
将$(this).remove()
替换为
$( ".fb-like" ).remove();
它将删除fb-like
类的元素。