2011-05-12 62 views
2

我想用其第一个孩子替换dom父母并删除所有其他孩子。它不工作。我得到了错误:“节点不能在层次结构的指定点插入”jquery替换第一个孩子的父母

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

回答

3

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

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