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(); 

https://jsfiddle.net/9pmhan8l/1/


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -