jQuery .unwrap Function

I was wrapping some content the other day in jQuery and couldn't find a good way to unwrap the elements, so after some digging I found some code close to what I was looking for, modified it a bit, and built an extension to make this whole process a heck of a lot easier.
The Extension
jQuery.fn.extend({ unwrap: function(){ return this.each(function(){ $(this.childNodes).insertBefore(this); }).remove(); } }); Usage
Simply call it just like any other jQuery function. For example, if I had previously wrapped an element (or even just some text) with , I would use the following code to unwrap it:
$('.example').unwrap(); Simple as that! You can find some other functions out there, but most are a lot heavier than they need to be. This should get the job done for almost any occasion - it's worked great for me so far.
Responses to this Article:
Loading Comments...
I am a web developer, designer, and consultant located in the La Crosse / Onalaska Wisconsin region with
over twelve years experience developing and managing projects ranging from large applications and cloud-based
business solutions to social/new media campaigns, to complete system and infrastructure implementation.