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).

Sahil Kkr
  • 195
  • 4
  • 24

1 Answers1

-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>
Mamun
  • 66,969
  • 9
  • 47
  • 59