I'm trying to add an element to the DOM using JavaScript. I have a ul
and I want to add a li
. Its nothing difficult using appendChild
but I want my li
to be more complicated.
This is the output that I'm trying to achieve:
<li>
<span class="author">Me</span>
<span class="message">Message...</span>
<span class="time">
<div class="line"></div>
15:21
</span>
</li>
let author = "me";
let message = "Message...";
let time = "15:21";
As you can see what I'm trying to achieve isn't just a basic li
with some text (innerHTML) but quite a big chunk of HTML code.
My question is how I can achieve to get this output using JavaScript. Or should I use some JavaScript library or something to make it easier?