[英]How to fix not working Jquery on a html page, that was dynamically loaded into a div?
[英]How to unload the HTML page loaded in div tagafter 5 sec using Jquery?
我在頁面中使用一些CSS跟隨div。 與此相關,我在其頂部和下方均沒有幾個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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.