5秒后删除新的div
16lz
2021-01-22
i want to add a div and after 5 seconds remove it. i tried
我想添加一个div,并在5秒后删除它。我试过了
$("#mainContentTD").prepend("<div style='color: #038a00; padding-bottom:10px;'>Your detailes where sucsesfuly... </div>").delay(5000).remove("this:first-child");
2 个解决方案
#1
29
You can use setTimeout
like this:
您可以像这样使用setTimeout:
setTimeout(function(){
$('#divID').remove();
}, 5000);
The 5000 (ms) means 5 seconds. You should replace divID
with your own div/element id.
5000(ms)表示5秒。您应该用您自己的div / element id替换divID。
You can make sure that the div exists first using length
:
您可以使用length确保div首先存在:
setTimeout(function(){
if ($('#divID').length > 0) {
$('#divID').remove();
}
}, 5000)
更多相关文章
- [置顶] JQuery datatables 使用Fixedcolumns固定列控件
- jQuery Ui Draggable在移动端浏览器不起作用解决方案
- html2canvas 识别 svg 解决方案
- HTML5用户身份认证源代码:注册、登录、会话保持的解决方案
- 用于在表中强制换行的PHP或HTML/CSS解决方案
- 如何实现分布式文件上传解决方案?
- 一套PHP做app接口的解决方案
- curl获取网页内容出现乱码或为空的解决方案,另附curl_getinfo函数
- PHP XAMPP配置PHP环境和Apache80端口被占用解决方案