Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript create ul li from array

var options = [
        set0 = ['Option 1','Option 2'],
        set1 = ['First Option','Second Option','Third Option']
    ];

function makeUL(array) {
    // Create the list element:
    var list = document.createElement('ul');

    for (var i = 0; i < array.length; i++) {
        // Create the list item:
        var item = document.createElement('li');

        // Set its contents:
        item.appendChild(document.createTextNode(array[i]));

        // Add it to the list:
        list.appendChild(item);
    }

    // Finally, return the constructed list:
    return list;
}

// Add the contents of options[0] to #foo:
document.getElementById('foo').appendChild(makeUL(options[0]));
Comment

PREVIOUS NEXT
Code Example
Javascript :: validator pattern angular for number only 
Javascript :: afficher un div qui etait cache en javascript 
Javascript :: js get transition duration 
Javascript :: jquery insert text into input 
Javascript :: material ui input placeholder color 
Javascript :: jquery mouseup javascript 
Javascript :: check if string is valid json dart 
Javascript :: has decimal javascript 
Javascript :: how to make something spawn on a random x axis p5.js 
Javascript :: window.open javascript auto close 
Javascript :: check if element has childs jquery 
Javascript :: js string pop last character 
Javascript :: prevent reload javascript 
Javascript :: timer in java script 
Javascript :: javascript loop through object values 
Javascript :: requirenativecomponent rnsscreen was not found in the uimanager 
Javascript :: javascript make beep 
Javascript :: input type number react native 
Javascript :: get link js 
Javascript :: javascript getelementbyid disable 
Javascript :: username regex 
Javascript :: node js load animation 
Javascript :: increase-memory-limit not working node 
Javascript :: how replace 0 without replace 10 in js 
Javascript :: get h1 text javascript 
Javascript :: es6 
Javascript :: allow only letters javascript 
Javascript :: nestjs cli create project 
Javascript :: console.time js 
Javascript :: javascript how to sort nodes from dom 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =