0
<div id="div-02">Here is div-02</div>
var el = document.getElementById('div-02');
el.remove(); // Removes the div with the 'div-02' id

setTimeout(() => {
el.add?... },5000)

I want to remove the element for 5 seconds and make it same as it was previously( before removing it).

4
  • 2
    maybe try display: none Commented Oct 18, 2018 at 13:43
  • 3
    Just asking for clarification, you want to remove it for 5 seconds and then restore it? If so you can just hide and show Commented Oct 18, 2018 at 13:43
  • Hi, can you use jquery or pure js? Commented Oct 18, 2018 at 13:45
  • I am working on ANgular project so probably pure js but hide and show solved my problem I was going in wrong direction Commented Oct 18, 2018 at 14:00

1 Answer 1

-1

You can take the element in a temporary variable so that you can append that after the time ends:

var temp = document.getElementById('div-02');
var el = document.getElementById('div-02');
el.remove(); // Removes the div with the 'div-02' id
setTimeout(() => {
  document.body.append(temp); 
},5000)
<div id="div-02">Here is div-02</div>

But the ideal solution would be hide/show using the style property of the element:

var el = document.getElementById('div-02');
el.style.display = 'none';
setTimeout(() => {
  el.style.display = 'block';
},5000)
<div id="div-02">Here is div-02</div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.