Jquery用第一个子代替父母

时间:2011-05-12 08:49:48

标签: jquery jquery-selectors

我正在尝试用它的第一个孩子替换dom父母并删除所有其他孩子。它不起作用。我收到错误:“节点无法插入层次结构中的指定点”

$("#over1").replaceWith($(this).children()[0]); 

1 个答案:

答案 0 :(得分:3)

this未引用#over1元素。相反,你应该这样做:

$("#over1").replaceWith(function() { return $(':first', this); });
相关问题