🚨 Time is Running Out: Reserve Your Spot in the Lucky Draw & Claim Rewards! START 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.