createElement( )
As you’d expect, the createElement( )
method (which is used on the document
object) creates and returns a new element. To build a div
for example, do the following:
var new_div = document.createElement( 'div' );
This assigns your newly created element to the variable new_div
. To actually see the newly created div
on the page, we should probably put some content in it.
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.