createTextNode( )
Using the createTextNode( )
method (also on the document
object), we can generate a text node to attach to our newly created div
. Let’s assign the new text node to the variable text
:
var text = document.createTextNode( 'This is a new div' );
We now have two newly created nodes, but they aren’t connected. To do that, we need to use the DOM to make the text node a child of the div
. We can accomplish this in a number of ways.
Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.