i'm trying to add a list element to an existing ul using a function from an onclick like this:
<span style="color:red;">Bob</span>
If i hard code it in the HTML it works fine:
<ul id="LsUL">
<li><span style="color:blue;">Joe</span></li>
<li><span style="color:green;">Frank</span></li>
</ul>
But using a function it dose not work
function changeText2() {
var entry = document.createElement('li');
entry.appendChild(document.createTextNode('<span style="color:red;">Bob</span>'));
document.getElementById("LsUL").appendChild(entry);
}
changeText2();
<ul id="LsUL">
<li><span style="color:blue;">Joe</span></li>
<li><span style="color:green;">Frank</span></li>
</ul>
The output should be like this:
- Joe (blue)
- Frank (green)
- bob (red)
But I get this:
Joe (blue)
Frank (green)
<span style="color:red;">bob</span>
I cant seem to get it to work any ideas? Thanks.