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.