5秒后删除新的div [英] remove new div after 5 seconds

查看:184
本文介绍了5秒后删除新的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要添加一个div,5秒钟后将其删除. 我试过了

i want to add a div and after 5 seconds remove it. i tried

$("#mainContentTD").prepend("<div style='color: #038a00; padding-bottom:10px;'>Your detailes where sucsesfuly... </div>").delay(5000).remove("this:first-child");

推荐答案

您可以像这样使用setTimeout:

setTimeout(function(){
  $('#divID').remove();
}, 5000);

5000(毫秒)表示5秒.您应该用自己的div/element ID替换divID.

The 5000 (ms) means 5 seconds. You should replace divID with your own div/element id.

您可以使用length确保div首先存在:

You can make sure that the div exists first using length:

setTimeout(function(){
  if ($('#divID').length > 0) {
    $('#divID').remove();
  }
}, 5000)

这篇关于5秒后删除新的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆