ipid
ipid

Reputation: 652

What's the difference between `document.createTextNode` and `new Text()`?

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

Answers (1)

CertainPerformance
CertainPerformance

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

Related Questions