我希望單擊時將列表項移動到div,反之亦然。但似乎只有從源碼加載的元素才能被移動。如何刪除jQuery添加的元素?
我該怎麼做? 謝謝。
<div class="green">
<ul id="selectable">
<li class="content-item">Item A</li>
</ul>
</div>
<div class="red">
<span class="selected-item">Item 1</span>
<span class="selected-item">Item 1</span>
<span class="selected-item">Item 1</span>
<span class="selected-item">Item 1</span>
<span class="selected-item">Item 1</span>
<span class="selected-item">Item 1</span>
<span class="selected-item">Item 1</span>
</div>
<script>
$(".selected-item").click(function() {
var text = "<li class='content-item' >"+$(this).text()+"</li>";
$(".green #selectable").prepend(text);
$(this).remove();
});
$(".content-item").click(function() {
var text = "<span class='selected-item'>"+$(this).text()+"</span>";
$(".red").append(text);
$(this).remove();
});
</script>
http://jsfiddle.net/wGz8s/112/