DEV Community

Cover image for jQuery Clear innerHTML
ProgrammerMoney
ProgrammerMoney

Posted on • Updated on

jQuery Clear innerHTML

TL;DR Summary

Most important thing you need to remember when trying to clear innerHTML with jQuery is that you do not touch innerHTML at all.

What you need to do is use .html() function that is already available in jQuery.

Here is the code example:

<div id="container">
  <div class="myclass">HTML one</div>
  <div class="myclass">HTML two</div>
  <div class="myclass">HTML three</div>
</div>

<script>
  // this is how you can read HTML
  $('#container').html();

  // this is how you delete HTML
  $('#container').html('');
</script>
Enter fullscreen mode Exit fullscreen mode

And that is all you need to know about clearing innerHTML with jQuery.

Until next time,
Will
Senior Developer & SEO Algo Specialist

Top comments (0)