I am trying to create elements with dynamic class value, so far unsuccessful. Here's code:
let sender = "alex";
let message = "testMsg";
let time = "15:30";
let msg = $('<span>')
.append($('<span>', {class : 'timestamp'}, {text: time}))
.append($('<p>', {class : sender}, {text: message}));
Results in the following:
<span>
<span id="timestamp"></span>
<p></p>
</span>
Which is confusing, because I read here that this more "elegant" way allows for variables to be used as dynamical properties. What am I missing here?
Thanks
Solved: Turns out that I tried to give 3 paramethers to .append() function. Read bellow for solutions and explanation.
attr()letinstead ofvar?