Consider my parent div is parentDiv and it contains five child divs
<div id="parentDiv">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
How to empty the child elements parentDiv using jquery....
EDIT:
What is the diff between empty() and remove()? what should i use?
$("#parentDiv").empty(); from here
.empty() removes all of the children of the selected element(s); .remove() removes the selected element(s) themselves as well as any children.
Thus, $("#parentdiv").empty(); makes the most sense here, because you want to remove the children but not the parent div.
Have you tried $("#parentDiv div").remove() or $("#parentDiv").empty() ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With