Create ul and li elements in javascript.

后端 未结 4 1426
孤街浪徒
孤街浪徒 2020-12-08 15:51

I am trying to create ul and li element in my codes by using javascript. I have following:

var test=document.createElement(\'section\');
test.setAttribute(\'         


        
4条回答
  •  误落风尘
    2020-12-08 16:12

    Great then. Let's create a simple function that takes an array and prints our an ordered listview/list inside a div tag.

    Step 1: Let's say you have an div with "contentSectionID" id.

    Step 2: We then create our javascript function that returns a list component and takes in an array:

    function createList(spacecrafts){
    
    var listView=document.createElement('ol');
    
    for(var i=0;i

    Step 3: Finally we select our div and create a listview in it:

    document.getElementById("contentSectionID").appendChild(createList(myArr));
    

提交回复
热议问题