这是我的两个div。
<div class="fb-like-box" id="fb-ONE" data-href="https://www.facebook.com/namePage1" data-width="100" data-height="100" data-colorscheme="light" data-show-faces="true" data-header="true" data-stream="false" data-show-border="true"></div>
<div class="fb-like-box" id="fb-TWO" data-href="https://www.facebook.com/namePage2" data-width="100" data-height="100" data-colorscheme="light" data-show-faces="true" data-header="true" data-stream="false" data-show-border="true"></div>';下面是我删除div类fb-like-box的代码。
window.fbAsyncInit = function() {
FB.Event.subscribe('edge.create', function(response) {
$( ".fb-like-box" ).remove();
});
};我的div具有相同的类,但不具有相同的id。当我订阅一个时,我想删除它。我不能放入.fb- like -box,因为它删除了两个,即使我不喜欢另一个。我必须使用子/父吗?
谢谢
发布于 2014-09-10 17:21:29
你应该这样做:
更新代码:
window.fbAsyncInit = function(event) {
FB.Event.subscribe('edge.create', function(response) {
});
$(event.target.id).remove();
};请告诉我这个能不能用。
event.target.id获取调用事件的元素的id。
更多更新代码:
$(document).ready(function(){
$(".fb-like-box").click(function(){
$(this).remove();
});
});这应该是可行的
发布于 2014-09-10 17:27:05
window.fbAsyncInit = function(event) {
FB.Event.subscribe('edge.create', function(response) {
$(event.target.id).remove();
});
};更新JS:
window.fbAsyncInit = function() {
FB.Event.subscribe('edge.create', function(response) {
if (response == "https://facebook.com/pagename1"){
$("#fb-TWO").remove();
}else {
$("#fb-ONE").remove();
}
});
};HTML
<div class="fb-like-box" id="fb-ONE" data-href="https://www.facebook.com/pageName1" data-width="100" data-height="100" data-colorscheme="light" data-show-faces="true" data-header="true" data-stream="false" data-show-border="true"></div>
<div class="fb-like-box" id="fb-TWO" data-href="https://www.facebook.com/pageName2" data-width="100" data-height="100" data-colorscheme="light" data-show-faces="true" data-header="true" data-stream="false" data-show-border="true"></div>https://stackoverflow.com/questions/25761377
复制相似问题