How to remove children in jQuery?

In the following example

http://jsfiddle.net/pDsGF/

I want to remove only the 'child' class from the parent class. I tried

.remove($('parent').children('child'))

But it does not work

+8
jquery
source share
5 answers

You need periods to get elements by class, for one. For two, this syntax is incorrect.

 $('.parent .child').remove(); 

Here is a demo.

+13
source share

Do you want to remove the children (with the child class) of the parents (with the class "parent")?

 $('.parent').children('.child').remove(); 

Or simply:

 $('.parent .child')​.remove()​; 
+3
source share

Try $('.parent').find('.child').remove();​ http://jsfiddle.net/pDsGF/1/

Edit: In case I misunderstood, and you wanted to remove the try $('.parent').find('.child').removeClass('child')

+2
source share

This will do the trick.

 $('.parent .child').remove(); 

(minitech beat me :) :)

+1
source share

many ways: if you don’t have an identifier for the child, you can remove the children of my parent position:

 var p ='.parrent';//identify the parrent $('p').children('1').remove();//remove the child placed in ('1'); 

delete Directly [if you have an identifier]

 $('.parent .child').remove();//it removes child from the parent. 

if you don’t know what a parent is.

 var selector = '.child';//you must identify ONE child to find its parent var sP = $(selector).parent();//selecting the parent for this Child //now removing the Child [identifier = position of child] $(select).parent().children("5").remove(); 

In case you have too many children with the same class, but the parent version is for everyone. you can also remove Child by placing a child class

 //[._iNote] is the selector for the removing Element Here. $(select).parent().children("._iNote").remove(); 

This script removes only the selected child in the selected parity. if there are many children with the same identifier, then all of them will be deleted so [???] in this case you can create a custome attr to select the item [HTML5 only]. Example

 <p data-me="someThing-i-like"> [its a custom attr (data-me="someThing-i-like")] </p> 

in this case, to remove this item

 $("[data-me=someThing-i-like]").remove();// will work fine 

if you have any quistion about this post plz plz plz let me know [comment]

+1
source share

All Articles