I have a parent-container which it has heading, other divs, and mainly <section>.
I want to move <section> alone to its parent in each container.
My code is running as expected, but I need to remove all other elements which comes dynamically, Eg: table, p, b etc... and I am not sure, is this the correct way to do it or not. :(
The final code should be in below format:
<div class="parent-container">
<section>Original content 1</section>
</div>
<div class="parent-container">
<section>Original content 2</section>
</div>
<div class="parent-container">
<section>Original content 3</section>
</div>
$('.parent-container').each(function () {
jQuery(this).find('section').appendTo($(this));
jQuery(this).find('div').remove();
jQuery(this).find('h1').remove();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="parent-container">
<div class="pc-1">
<h1>Hello world</h1>
<div class="pc-2">
<section>Original content 1</section>
<p>Some more content</p>
</div>
</div>
</div>
<div class="parent-container">
<div class="pc-1">
<h1>Hello world</h1>
<div class="pc-2">
<section>Original content 2</section>
<p>Some more content</p>
</div>
</div>
</div>
<div class="parent-container">
<div class="pc-1">
<h1>Hello world</h1>
<div class="pc-2">
<section>Original content 3</section>
<p>Some more content</p>
</div>
</div>
</div>