简体   繁体   中英

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.

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. 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()

$('#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);
)};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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