如何只获取我已经遍历到的元素的下一个元素作为jQuery前缀。
对于每个.element- to -insert-into,我希望预先考虑该元素的下一个子元素。
以下内容不起作用。我相信我没有正确使用"this“:
jQuery('.element-to-insert-into').prepend(jQuery(this).next('.parent-element').children('child-id-like-to-prepend'))发布于 2020-09-09 18:13:47
您可以使用each循环:
jQuery('.element-to-insert-into').each(function(index, element) {
var $current = $(element);
$current.prepend($current.next('.parent-element').children('#child-id-like-to-prepend'));
// as ids are meant to be unique, you could just prepend the targeted id:
$current.prepend($('#child-id-like-to-prepend'));
});https://stackoverflow.com/questions/63809391
复制相似问题