Adding ID to LI Javascript -
so have following code set create li element when inputs box. want li element contain unique id begin list-item0 , go list-item1, etc every li created when types box , adds item. 
any idea how go doing this? don't know jquery complete beginner looking extremely basic can implement in code.
here's have far:
function additemfunction() {     document.getelementbyid("itemlist").innerhtml=document.getelementbyid("itemlist").innerhtml + '<li>' + addnewbox.value + '</li>';   }      
simply keep counter id outside function, create <li> element, set id , content, increment counter , append element itemlist.
var listitemcounter = 0;          function additemfunction() {     var li = document.createelement('li');     li.id = 'list-item' + listitemcounter++;     li.innerhtml = addnewbox.value;      document.getelementbyid('itemlist').appendchild(li); }      
Comments
Post a Comment