我想用jQuery动态生成的div标签添加由div生成的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);
});
});
的附加jQuery的div标签代码使用javascript div标签应该是这样的: block_element.append(NEW_ITEM);
但它给错误,因为我们不能绑定,因为我在同一行使用JavaScript和jQuery。有什么办法可以做到吗?
第二种解决方案将打破'removeChild'。 – bfavaretto 2012-02-27 04:26:30
即使第一个解决方案也不行 – Starx 2012-02-27 04:35:50