如何使用Jquery在5秒后卸载div标签中加载的HTML页面



我的页面中有下面的div和一些css。有了这个,我在上面和下面都有一些div。

HTML:

<div id="sentdiv"></div>

CSS:

#sentdiv{
margin-left: 13rem;
margin-right: 20rem;
width: 800px;
height: 600px;
padding: 50px;
}

然后我有一个ajax调用,在其中我加载一些html页面,如下所示。

JS:

$.post('/logme', function(resp) {
$("#sentdiv").load("success.html");
});

在这里,我想在5秒后卸载success.html,并保留div及其CSS。

我试过跟随

$("#sentdiv").delay(5000).replaceWith("<p>");
$("#sentdiv").delay(5000).fadeOut();

但是它正在移动下面的元素。我想保留div,只删除div的内容。

使用jquery方法.empty((

$("#sentdiv").empty();

setTimeout(function() {
$("#sentdiv").empty();
}, 5000)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="sentdiv">
<span>this will be removed in five seconds...</span>
</div>

最新更新