javascriptjqueryhtmldom-manipulation

How to clear all <div>s’ contents inside a parent <div>?


I have a div <div id="masterdiv"> which has several child <div>s.

Example:

<div id="masterdiv">
  <div id="childdiv1" />
  <div id="childdiv2" />
  <div id="childdiv3" />
</div>

How to clear the contents of all child <div>s inside the master <div> using jQuery?


Solution

  • jQuery('#masterdiv div').html('');