jQueryで生成されたdivタグをjavascriptのdivタグ要素で動的に追加したいとします。私のコードは次のようになります。jQueryで生成されたdivタグをjavascriptのdivタグ要素で動的に追加する方法
$(".remove_item").click(function(){
$(this).hide("fast", function(){
var id = $(this).parent().attr("id");
var remove_item_id = document.getElementById(id);
var block_element = document.getElementById("block");
block_element.removeChild(remove_item_id);
new_item = $("<div/>");
new_item.attr("id", "item");
new_item.attr("name", "item");
new_item.addClass("div_image");
new_item.append($("<img/>")
.addClass("image")
.attr("src", "/compare/sites/default/files/add_item.jpg")
.attr("height", 50)
.attr("width", 50));
new_item.append($("<span/>")
.addClass("new_item")
.click(function(){
$(this).parent().remove();
}));
block_element.append(new_item);
});
});
のdivタグは次のようになりますJavaScriptでのjQueryのdivタグを追加するためのコード: block_element.append(NEW_ITEM)。
私は同じ行にjavascriptとjQueryを使用しているのでバインドできないので、それは与えられたエラーです。それを行う方法はありますか?
第2の解決策は、「removeChild」を中断します。 – bfavaretto
最初のソリューションでも機能しません – Starx