I am facing an issue with the HTML structure in my application:
<div class="work-item">
<div class="image-container">
</div>
<div class="text-container">
</div>
</div>
<div class="work-item">
<div class="text-container">
</div>
<div class="image-container">
</div>
</div>
<div class="work-item">
<div class="image-container">
</div>
<div class="text-container">
</div>
</div>
<div class="work-item">
<div class="text-container">
</div>
<div class="image-container">
</div>
</div>
I am attempting to target elements with the text-container
class, and if it's the first element under work-item
, move it after the div with the image-container
class. So that the structure of every div element looks like:
<div class="work-item">
<div class="image-container">
</div>
<div class="text-container">
</div>
</div>
I initially tried removing it using this code:
$(".work-item .text-container:first-child").remove();
It worked as expected. However, when I attempted to move it with the following code, nothing happened:
$("#work .work-item .text-container:first-child").insertAfter($(this).parent()["last-child"]);
Can anyone help me identify what mistake I might be making here?