javascript - How to createText and append text to an existing element e.g. empty span? -
everywhere i've searched i've found ways append textnode after creating new element. example, they'll create new paragraph (p
) element, , afterwards append textnode new paragraph. want add textnode existing element (in case, empty span).
link code example , clarification http://pastebin.com/k1ebmr4z
<span class="span"></span> <!-- append textnode here -->
function newfunction(){ var textnode = document.createtextnode("ok"); // append `textnode` empty span here }
thanks in advance
as mentioned in comment, can add text node child of span using appendchild()
method.
for text can set innerhtml
property of span.
both examples in bin:
function newfunction(){ var span = document.getelementbyid('my-span'); var otherspan = document.getelementbyid('my-other-span'); span.innerhtml = 'yo text'; var textnode = document.createtextnode("ok"); otherspan.appendchild(textnode); }; newfunction();
Comments
Post a Comment