Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove inner divs from a parent div using jquery

Tags:

html

jquery

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?

like image 577
ACP Avatar asked Mar 30 '10 10:03

ACP


3 Answers

$("#parentDiv").empty(); from here

like image 113
AutomatedTester Avatar answered Nov 15 '22 02:11

AutomatedTester


.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.

like image 38
Amber Avatar answered Nov 15 '22 00:11

Amber


Have you tried $("#parentDiv div").remove() or $("#parentDiv").empty() ?

like image 20
Ivan Avatar answered Nov 15 '22 01:11

Ivan