I'm developing a Google Chrome extension and I want to add <li>
to <ul>
tag via JavaScript:
var newLI = document.createElement("LI");
var ul = document.getElementById('tag_list');
ul.appendChild(newLI);
newLI.innerHTML = "<a href=\"dddaaaa\">" + json + "</a>";
and HTML:
<template id="box#add-feeds">
<ul class="search-ac" id="tag_list" name="tag_list"></ul>
</template>
When I remove the <template>
tag this code works well but with this tag I have this error:
Cannot call method 'appendChild' of null
I can't remove the template tag so I have to change JavaScript code. Any idea about why getElementById
doesn't work if a tag is in a custom tag <template>
?