javascript - Jquery append() on another line? -
i thought simple code outputs spans on same line.
$("<p/>") .append($("<span/>", { class:"time", text: content.time })) .append($("<span/>", { class: "content", text: content.message }));
but since append these elements without newline, spans end needing manual spacing, isn't possible @ current scale.
<p><span class="time">now</span><span class="content">lorem ipsum ...</span></p>
how can force jquery manually append spans on new line? i've tried using .after
to.
edit:
i guess bit unclear, far .append("\n")
i'm looking for, if there better ways, i'm ears appending <br/>
tag not looking for.
<p> <span class="time">now</span> <span class="content">lorem ipsum ...</span> </p>
if want html element appeneded newline, can insert newline character, \n
, using .after()
method before appending second span
. in doing so, there space between words (since inline
span elements respect whitespace in markup).
$("p").append($("<span/>", { class: "time", text: content.time }).after('\n')).append($("<span/>", { class: "content", text: content.message }));
Comments
Post a Comment