チェックボックスの選択時に、チェックボックスに隣接するテキストノードにあるデータを移動しようとしています。私はjqueryを使用しています。私が試した方法と、受け取った結果を以下に示します。
<input class="item" type="checkbox" /> Category 1
<input class="item" type="checkbox" /> Category 2
<script>
$('.item').click(function(){
if($(this).attr('checked'))
{
$('#list').append("<span>" + $(this).next() + "<span><br/>")
//$(this).next() just writes "[object Object]"
//$(this).next().text() doesn't write anything
//Also tried $(this).nextSibling.nodeValue but throws "Cannot access property of undefined"
}
else
{
//This is remove the item from the list on uncheck
}
});
</script>