Reputation: 407
var span = document.createElement('span');
var text = document.createTextNode('my text');
// I know this does not work but you know what I mean:
var element = span + text;
parentElement.appendChild(element);
or with jQuert
$('#aDiv').append(element);
How do I add the text node AFTER the span? and then I just add the span with the text to another element that exists.
Upvotes: 1
Views: 53
Reputation: 77482
Append text
after span
, like so
parentElement.appendChild(span);
parentElement.appendChild(text);
Or with jQuery
$(parentElement).append(span);
$(parentElement).append(text);
Upvotes: 3