I found a few posts referencing something similar but I could not get it working..
Simply I am trying to create a List as shown below.
<ul>
<li><a href="https://www.google.com">foo</a> </li>
<li><a href="https://www.google.com">bar</a></li>
</ul>
However when generating it through JS I get one of the following.
<ul>
<li>
<a href="https://www.google.com"></a>
foo
</li>
<li>
<a href="https://www.google.com"></a>
bar
</li>
</ul>
OR
<ul>
<li>
foo
<a href="https://www.google.com"></a>
</li>
<li>
bar
<a href="https://www.google.com"></a>
</li>
</ul>
With the JS code provided.
function addListItem(id, str, url) {
var list = document.getElementById(id);
var el = document.createElement("LI");
var text = document.createTextNode(str);
if (url !== "") {
var a = document.createElement("A");
a.setAttribute("href", url);
el.appendChild(text);
el.appendChild(a);
} else {
el.appendChild(text);
}
list.appendChild(el);
}
How would I go about doing this?