我有一些由 CMS 生成的代码:
<div class="block">
<a class="link" href="#">Link</a>
<h4>Header here</h4>
<div class="text">Some text here</div>
</div>
我需要将链接移动到文本 div 之后。我试过这个:
$(document).ready(function() {
$('.block').each(function() {
$('.block a.link').insertAfter('.block div.text');
});
});
但这只会导致链接重复大约 10 次(循环次数。
我尝试使用 $(this) 但我不太明白如何编写正确的语法来在函数中附加 a.link ......就像这样:
$(this).a.link.insertAfter($(this).div.text);