简体   繁体   English

jQuery删除指定Div(Facebook标记)中的所有内容

[英]JQuery Remove all content inside a specified Div (Facebook Tag)

I am using this: 我正在使用这个:

$('#myLink').click(function () {
    $('#MainDIV').empty();
});

Where: 哪里:

<div id="MainDIV">
    <fb:like href="somelinketc">....</fb:like>
</div>

I need everything inside <div id="MainDIV"> to disappear but I'm checking firefox and it's all still there. 我需要<div id="MainDIV">中的所有内容消失,但我正在检查Firefox,并且所有内容仍然存在。

Try it in this way. 以这种方式尝试。

$(document).ready(function(){

$('#myLink').click(function(){

document.getElementById('MainDIV').innerHTML="";
});
});

I think this is an easy way to overwrite the existing data in the element in which you want to make it disappear or change the contents according to your requirements. 我认为这是一种简单的方法,可以覆盖要使其消失或根据需要更改内容的元素中的现有数据。

There's an error in your .click() function. .click()函数中存在错误。 It should end with the parenthesis like this: 它应该以这样的括号结尾:

});

and not like this: 而不是这样:

)};

Should fix it. 应该修复它。

You should be preventing the click action of the link with preventDefault() 您应该使用preventDefault()防止链接的点击动作

$('#myLink').click(function (e) {
    e.preventDefault();
    $('#MainDIV').empty();
});

Also I am not sure but your post above has a typo. 我也不确定,但是您上面的帖子有错字。 )} should be }) . )}应该是})

$("#MainDIV").html('');

这将清除div的所有内容。

$('#myLink').click(function () {
    $('#MainDIV').hide(1);
)};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM