Reputation: 652
Both create a new Text node. It seems that the only difference is the browser compatibility. Is there any other differences?
Upvotes: 1
Views: 460
Reputation: 371203
It would appear that, according to the DOM standard, there's almost no difference:
text = new Text([data = ""])
Returns a new Text node whose data is data. (link)
text = document . createTextNode(data)
Returns a Text node whose data is data. (link)
except for the fact that the argument is optional for the constructor, but required for createTextNode
. (Omitting the argument for createTextNode
will throw.)
new Text();
console.log('first line worked');
document.createTextNode(); // throws
Upvotes: 3