在追加新元素之前,Im当前无法清除容器div。 (整个div在empty()
时被擦干净,我不想要这个,我简单地想删除现有的书架元素。是否有什么我做错了?和/或可能是因为“文本/模板”脚本?)在追加之前清除div
HTML片段
<div class="component">
<ul id="Maincontainer" class="align">
<script type="text/template" id="template">
<li id="bookHolder" class="bookHolder">
<figure class="book">
<!-- Front -->
<ul class="hardcover_front">
<li>
<img src="{{imgURL}}" alt="" width="100%" height="100%">
</li>
<li></li>
</ul>
</figure>
</li>
</script>
</ul>
</div>
JQUERY片断
$.get("URL", function(data) {
var entry = $(data).find("entry");
entry.each(function() {
var template = $("#template").html();
//$("#Maincontainer").remove(); - >clear whole div, appended elements not show
//$("#Maincontainer").remove("#bookHolder"); -> Div not cleared
$("#Maincontainer").append(template.replace("{{bookName}}",
bookName).replace("{{summary}}", summary).replace("{{price}}", price).replace("{{seller}}", artist).replace("{{imgURL}}", image)
.replace("{{href}}", href).replace("{{category}}", category));
});
});
是否要删除类“bookHolder”中的所有'li'元素?我是对的? – erikscandola
@erikscandola正确 –