The JQuery provide efficient ways for wrapping, replacing, and removing DOM contents. These are given below :
Click here to know about wrapping DOM
The methods in this category allow us to delete elements from the DOM.
.detach( )
This method remove the filtered element from the DOM.
Example :
$("p").detach();
It will remove all the 'p' element from the DOM.
.empty( )
It will remove all the child nodes from the filtered elements.
Example :
$("p").empty();
It will remove all the child nodes from the 'p'.
.remove( )
It will remove the set of matched elements from the DOM. We use .remove() when we want to remove the element itself, as well as
everything inside it.
Example :
$('.hello').remove(); .unwrap( )
The .unwrap() method removes the element's parent from the matched set .It leaves the matched element at their place.
Example :
$("p").unwrap();
This script removes the parent of 'p'.
The methods fall under this category is used to replace the Dom content from new content.
.replaceAll( )
This method replace all the filtered element with provided element.
Example :
$('<h2>New heading</h2>').replaceAll('.inner');
It replace all the element of 'inner ' class with '<h2>New
heading</h2>'.
.replaceWith( )
This method replace each element in the set of matched elements with the provided new content.
Example :
$('.second').replaceWith('<h2>New heading</h2>'); '<h2>New heading</h2>'.
Learn from experts! Attend jQuery Training classes.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Wrapping, replacing, and removing content
Post your Comment