我试图克隆树,从中删除一个元素,然后将结果追加到新的地方.但问题是元素没有被删除,它总是附加原始树.
$(".js-parent-trigger").click(function() {
var commentForm = $("#js-add-comment-wrapper").clone(true).css("margin", "10px").remove(".js-add-comment-title");
$(this).parents(".js-comment-wrapper").append(commentForm);
return false;
});
Run Code Online (Sandbox Code Playgroud)
$(".js-parent-trigger").click(function() {
var commentForm = $("#js-add-comment-wrapper").clone(true).css("margin", "10px");
commentForm.find(".js-add-comment-title").remove();
$(this).parents(".js-comment-wrapper").append(commentForm);
return false;
});
Run Code Online (Sandbox Code Playgroud)