append - How to add a list item in the middle of a list with JQuery -


i have list 2 items, want add additional items after first item when content loaded. how done? can add items, show on end of list. have call or use list element array?

first create new list item (<li>) , populate list item content. think need define position of list item before or while add li item.

if(x > 0){     $('<li></li>').attr('id','liadult_'+x).appendto($("ul:#uladultlist"));    //$("ul:#uladultlist").add($('<li></li>').attr('id','liadult_'+x)).after($('#liadult_0'));    $('<img/>').attr({'id':'imgadultavatar_'+x,'src':'./images/person_20x20.jpg','class':'imgavatar','title':'the persons avatar','alt':'avatar adults'}).appendto($('#liadult_'+x));    $('<span></span>').attr({'id':'sadultfirstname_'+x,'class':'sadultline'}).html(xdata.adults[x].personfirstname).appendto($('#liadult_'+x));    $('<span></span>').attr({'id':'sadultlastname_'+x,'class':'sadultline'}).html(xdata.adults[x].personlastname).appendto($('#liadult_'+x));      $('<span></span>').attr({'id':'sadultparent_'+x,'class':'sadultline'}).html(xdata.adults[x].guardianrole).appendto($('#liadult_'+x));    $('<span></span>').attr({'id':'sadultcellphone_'+x,'class':'sadultline'}).html(xdata.adults[x].personcellphone).appendto($('#liadult_'+x));    $('<input/>').attr({'id':'personid_'+x,'type':'hidden'}).val(xdata.adults[x].personid).appendto($('#liadult_'+x));    $('<a></a>').attr({'id':'lnkadultprofile_'+x,'href':'#','name':'lnkadultprofile_'+x,'title':'edit adult profile'}).html('profile').appendto($('#liadult_'+x)); } 

to add new item after first one:

$('li:nth-child(1)').append('<li>new item</li>'); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -