🚨 $100K in Sight: Follow Bitcoin’s Final Push Live! TRACK NOW

Code has been added to clipboard!

jQuery .unwrap(): Remove Parents of HTML Elements

Reading time 1 min
Published Jan 24, 2018
Updated Oct 1, 2019

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.

Example
$("button").click(() => {
    $("a").unwrap();
});

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.