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

2514 views javascript

I have following div in my page with some css. with this I have few div on top and below it.


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


    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.


$.post('/logme', function(resp) {

here I want to unload the success.html after 5 sec and keep the with its CSS.

I have tried following


but It is moving the elements below it. I want to keep div and just remove the contents of div.

answered question

delay() is not a replacement for setTimeout(), as specifically noted in the API. delay() only affects the timing of animations that jQuery performs using it's internal animation queue.

1 Answer


use the jquery method .empty()


setTimeout(function() {
}, 5000)
<script src=""></script>
<div id="sentdiv">

<span>this will be removed in five seconds...</span>


posted this

Have an answer?


Please login first before posting an answer.