JavaScript - Turning an array into a list -


i want able turn array, consists of names entered user, unordered list list presents names on first list item. how separate names onto different list items?

this have:

function createlist(){     var list = document.getelementbyid("list");     var li = document.createelement("li");     var input = document.getelementbyid("q8").value;     var strcomma = input.split(",");     console.log(strcomma);     var = 0;     (i; < strcomma.length; i++){         var el = document.createtextnode(strcomma[i]);         li.appendchild(el);         list.appendchild(li);     } } 

that should trick

function createlist(){     var list = document.getelementbyid("list");     //var li = document.createelement("li");     var input = document.getelementbyid("q8").value;     var strcomma = input.split(",");     console.log(strcomma);     var = 0;     (i; < strcomma.length; i++){         var el = document.createtextnode(strcomma[i]);         var li = document.createelement("li");         li.appendchild(el);         list.appendchild(li);     } } 

that way creating new li element , appending same existing ul element. in way, declared li outside loop, referenced same li element every time.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -