0

How do I remove all the contents inside my mainDiv?

<div id='mainDiv'>
   <fieldset>
       <div>
           <input type='text'>
           <select></select>
       </div>
   </fieldset>
</div>
kevin_marcus
  • 277
  • 1
  • 5
  • 19
  • 4
    Possible duplicate of [Remove all child elements of a DOM node in JavaScript](https://stackoverflow.com/questions/3955229/remove-all-child-elements-of-a-dom-node-in-javascript) – Domino Nov 22 '17 at 03:06
  • You can use 1 line code: if using pure javascript try:`document.getElementById('mainDiv').innerHTML = '';` if using jQuery try: `$('#mainDiv').html('');` – Anph Nov 22 '17 at 03:08

1 Answers1

0
document.querySelector('#mainDiv').innerHTML = '';
Geuis
  • 41,122
  • 56
  • 157
  • 219