DEV Community

Cover image for jQuery Clear innerHTML

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>

  // this is how you can read HTML

  // this is how you delete HTML
Enter fullscreen mode Exit fullscreen mode

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

And if you want to speed up your coding career then check out my website for more info.

Until next time,
Senior Software Developer

Discussion (0)