What is the best way to create new text node and append it to the DOM?
I'm currently using this:
$('#someDiv').append(document.createTextNode('Some text'));
but is it the best way? Are there any other alternatives?
UPDATE
after checking the jQuery code I found that my variant probably the best...
here is how .text()
function implemented in jQuery:
text: function( value ) {
return jQuery.access( this, function( value ) {
return value === undefined ?
jQuery.text( this ) :
this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
}, null, value, arguments.length );
},
so, .text()
function calls .createTextNode()
method, so if you wish to save on calling extra operations, it's better to use direct text's node .append()