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.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 28/01/2021
3176 People Used
Only 97 Left
Rating
5.0