I'm struggling to move an element into the next element in the DOM. I can move it but it keeps repeating itself into the other div's with the same class.
This is my HTML:
<p>The first text that needs to be moved</p>
<div class="tmb">
<span class="price">500</span>
</div>
<p>Second text that needs to be moved</p>
<div class="tmb">
<span class="price">500</span>
</div>
What I want to happen is that the first p
element will be inserted after the first .price
element. The second p
element will be inserted after the second .price
element. I can't give the p
elements a class because they are created dynamically.
I have this jQuery:
$(".tmb").prev("p").insertAfter("span.price");
But this moves the p
element after every .price
element, which is logically. I just want it to move after the first .price
element that it comes across in the DOM.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…