I know this is a simple work around but I couldn’t find the right path. Please help!
I have a HTML structure like this
<div class="main">
<div class="parent">
<div class="child1">some content</div>
<div class="child2"><span class="grand-child1">some content</span></div>
</div>
<img src="image.jpg" />
</div>
<div class="main">
<div class="parent">
<div class="child1">some content</div>
<div class="child2"><span class="grand-child1">some content</span></div>
</div>
<img src="image.jpg" />
</div>
<div class="main">
<div class="parent">
<div class="child1">some content</div>
<div class="child2"><span class="grand-child1">some content</span></div>
</div>
</div>
Now I want to append the <img> inside the grand-child1 <span> on 1st two <main> divs.
If I use the following jQuery <img> are appearing twice in all <main> divs
$("img").appendTo(".grand-child1");
So, I have used each function like this. But nothing works for me.
$(".main img").each(function () {
jQuery(this).find('img').appendTo(this).closest(".grand-child1");
});