jQuery unwrap: Main Tips
- jQuery
.unwrap()
removes parents of the selected HTML elements. - After you make jQuery remove parent elements, the function returns the unwrapped content.
- The function opposite to unwrap jQuery offers is .wrap().
Using .unwrap()
The .unwrap()
jQuery function removes ancestor elements of the matched elements.
To make jQuery remove parent elements, you don't need to define any arguments:
$(selector).unwrap();
The following syntax sets a selector (defined in a string) to check the parent element against:
$(selector).unwrap([selector]);
Remember: if the selector and parent do not match, unwrapping will not occur.