Google Chrome extension dynamic list creating problem

185 Views Asked by At

Here is popup.html file :

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <div id="mList"></div>
    <script src="util.js"></script>
</body>
</html>

And here is util.js :

var options = ['','Second Option','Third Option'];

function makeUL(array) {
var list = document.createElement('ul');

/*
chrome.storage.sync.get(null, function(items) {
        var allKeys = Object.keys(items);
        allKeys.forEach(function(key) {
            console.log(key);
            options.push(key);
        });
   });
 */


for(var i = 0; i < array.length; i++) {
    var item = document.createElement('li');

    item.appendChild(document.createTextNode(array[i]));

    list.appendChild(item);
}

return list;
 }

 document.getElementById('mList').appendChild(makeUL(options));

Whenever I try to create the list dynamically the portion of the code commented, it doesn't work. It just gives me an empty HTML. But if I keep the code what it is currently, it works fine.

How this problem can be resolved ?

Here is full project link.

0

There are 0 best solutions below