In the following example
http://jsfiddle.net/pDsGF/
I want to remove just class 'child' from class 'parent'. I have tried
.remove($('parent').children('child'))
But it doesn't work
The empty() method removes all child nodes from the set of matched elements.
Given an HTML element and the task is to add and remove multiple classes from it using JQuery. Approach: First select the element to which multiple classes will be added. Then use addClass() method to add multiple classes to the element and removeClass() method to remove multiple classes.
jQuery remove() Method The remove() method removes the selected elements, including all text and child nodes. This method also removes data and events of the selected elements. Tip: To remove the elements without removing data and events, use the detach() method instead.
The empty() method removes all child nodes and content from the selected elements.
You need periods to get elements by class, for one. For two, that syntax isn't correct.
$('.parent .child').remove();
Here's a demo.
Do you want to remove the childs (with a class "child") of parents (with a class "parent")?
$('.parent').children('.child').remove();
Or simply:
$('.parent .child').remove();
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