[jQuery] absolute beginner question: $() create versus select
Hi,
having started learning jQuery yesterday, I'l already struggling with
the creation of new elements.
Given teh following html:
<ul id="existinglist">
<li>first item</li>
<li>seconditem</li>
<li>thirditem</li>
</ul>
<div class="vb" id="demo"></div>
I want to create a NEW list in the div 'demo' from an array. My code:
var arrPersonen = ['jan', 'pol', 'carole', 'ilse', 'piet']
$(document).ready(function(){
var list= $('ul');
$.each(arrPersonen,function(i,n){list.append('<li>'+n+'</li>')});
$('#demo').append(list)
});
This did not what I expected: it took the existing list and moved it
into 'demo', while adding new listitems.
I wanted $('ul') to produce a new element...???
and is there a better way to 'chain' this?
appreciate your help, Jan