This article mainly introduces how to dynamically create a div using Javascript. it is a typical application of javascript node operations and has great practical value, for more information about how to create a dynamic p in Javascript, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
The code is as follows:
Native javascript creates p
Script
Window. onload = function (){
Var Op = document. createElement ("p"); // Create a p
Var Ospan = document. createElement ("span"); // Create a span
Op.style.css Text = "width: 200px; height: 200px; background: #636363;
Text-align: center; line-height: 220px "; // create the css style of p
// Op. id = "box"; // The id of the created p is box.
// Op. className = "Box"; // The class of p is Box
Op. appendChild (Ospan); // Create a span in p
Document. body. appendChild (Op); // Create a p in the body
}
Script
I hope this article will help you design javascript programs.