JSFiddle - React, Tailwind, and code Playground
HTML
<li class="foo">
<div>
<ul>
<li>
<div>
<a href="#">Link</a>
</div>
</li>
</ul>
</div>
</li>
JavaScript
$.fn.unwrapTimes = function(times){
var unwrapCount = times;
return this.each(function(){
var $this = $(this);
for(var i=0;i<unwrapCount;i++){
$this.unwrap();
}
});
};
$(".foo a").unwrapTimes(4);