简体   繁体   English

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

[英]How to unload the HTML page loaded in div tagafter 5 sec using Jquery?

I have following div in my page with some css. 我在页面中使用一些CSS跟随div。 with this I have few div on top and below it. 与此相关,我在其顶部和下方均没有几个div。

HTML: HTML:

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

CSS: CSS:

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

}

Then I have a ajax call where in I am loading some html page like below. 然后我有一个ajax调用,其中我正在加载一些如下所示的html页面。

JS: JS:

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

here I want to unload the success.html after 5 sec and keep the div with its CSS. 在这里,我想在5秒钟后卸载success.html,并保留div及其CSS。

I have tried following 我尝试了以下

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

but It is moving the elements below it. 但是它正在移动它下面的元素。 I want to keep div and just remove the contents of div. 我想保留div,只删除div的内容。

use the jquery method .empty() 使用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> 

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

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