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?
jQuery's empty()
function does just that:
$('#masterdiv').empty();
clears the master div
.
$('#masterdiv div').empty();
clears all the child div
s, but leaves the master intact.
jQuery('#masterdiv div').html('');